Skip to content

hyeomans/document-vault-safe-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Document Vault Safe Errors

Small Go demo project showing secure error handling in a layered application:

  • HTTP handlers translate service errors into safe JSON responses.
  • Services validate input and map repository failures to domain-safe error codes.
  • Repository code keeps low-level SQLite details away from API clients.

Inspiration

This project is based on the JetBrains GoLand post on secure error handling in Go:

Run

go mod tidy
go run ./cmd/api

Example requests

curl -i http://localhost:8080/health

curl -i -H 'X-User-ID: alice' \
  -H 'Content-Type: application/json' \
  -d '{"title":"Plans","content":"internal notes"}' \
  http://localhost:8080/documents

curl -i -H 'X-User-ID: bob' http://localhost:8080/documents/1

curl -i -H 'X-User-ID: alice' http://localhost:8080/demo/internal-error

The /demo/internal-error route is intentionally unsafe internally and demonstrates that:

  • clients only receive a generic INTERNAL response with a request ID
  • logs keep the internal cause for debugging

About

Small Go demo project showing secure error handling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages