Documentation
¶
Overview ¶
Package errors provides shared sentinel errors and gRPC mapping for paper-board services. All public service errors should wrap one of these sentinels so callers can use errors.Is for routing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrConflict = errors.New("conflict") ErrPermissionDenied = errors.New("permission denied") ErrInvalidInput = errors.New("invalid input") ErrRateLimited = errors.New("rate limited") ErrInternal = errors.New("internal error") )
Sentinel errors.
Functions ¶
func FromGRPCStatus ¶
FromGRPCStatus converts a gRPC status error back to a wrapped sentinel. Useful in client code to use errors.Is across the wire.
func Kind ¶ added in v0.2.0
Kind returns a snake_case slug identifying the sentinel an error wraps. Used by sdk/httpmw to derive HTTP error codes ("<svc>.<kind>") and by sdk/log.ErrorAttrs to populate the "error.kind" attribute.
Returns "internal" for nil-wrapped or unknown errors so callers do not need to pre-classify.
func Message ¶ added in v0.2.0
Message returns the canonical user-facing message for the sentinel an error wraps. Mirrors Kind. Use for HTTP error envelopes; the wrapped chain detail goes only to logs (avoid leaking internal context to clients).
func ToGRPCStatus ¶
ToGRPCStatus maps a wrapped sentinel error to a gRPC status. Used by service handlers to convert internal errors into RPC responses.
if err := repo.Get(ctx, id); err != nil {
return nil, errors.ToGRPCStatus(err)
}
func ToHTTPStatus ¶ added in v0.1.2
ToHTTPStatus maps a wrapped sentinel error to an HTTP status code. Used by sdk/httpmw.HandleErr as the central HTTP error boundary.
Mapping:
ErrNotFound → 404 ErrConflict → 409 ErrUnauthorized → 401 ErrPermissionDenied → 403 ErrInvalidInput → 400 ErrRateLimited → 429 ErrUnavailable → 503 ErrInternal → 500 nil or unknown → 500
Example:
if err := repo.Get(ctx, id); err != nil {
http.Error(w, err.Error(), errors.ToHTTPStatus(err))
return
}
Types ¶
This section is empty.