Documentation
Errors
Map domain errors to stable API responses.
Overview
Centralized error mapping keeps client contracts predictable.
Example
Go
if errors.Is(err, store.ErrNotFound) {
return c.JSON(404, apiError("resource not found"))
}Best Practices
- Return machine-readable error codes.
- Log root causes with request IDs.
Common Pitfalls
- Leaking internal stack traces in API responses.
- Using inconsistent status codes for similar failures.