Documentation
¶
Overview ¶
Package errmodel is the one error model every AuthKit package speaks (ak#290): a Code, an Error carrying that code plus its HTTP status, an optional offending param, machine metadata and a cause, and the catalog that fixes each code's status and message. It sits below the root package so documents (which root imports) can define its codes on the same model.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultParam ¶
DefaultParam is the catalog's field name for a validation code, if any.
Types ¶
type Code ¶
type Code string
Code is a stable, snake_case wire error code.
func Define ¶
Define registers a code with its HTTP status and message and returns it. Package-level var initializers call it, so every code is in the catalog before any handler runs. Redefining a code is a programming error.
func DefineParam ¶
DefineParam is Define for a validation code that always concerns one request field: the param is filled in when an Error carries none.
type Error ¶
type Error struct {
Code Code
Status int
Param string
Meta map[string]any
// contains filtered or unexported fields
}
Error is the one error value: Code identifies it (errors.Is compares codes), Status is the HTTP status the catalog fixed for the code (an explicit WithStatus overrides it per site), Param names the offending request field, Meta carries machine-readable context, and the cause is the wrapped error.
func E ¶
E builds an Error for a catalogued code (status from the catalog; an uncatalogued code is a 500).
func Recode ¶
Recode re-tags err with another code (a route-specific wire divergence), keeping err as the cause and carrying an inner Error's Param/Meta forward.
func (*Error) Is ¶
Is matches any *Error with the same Code, so a sentinel var, a fresh E() and a wrapped copy are all one identity.
type Option ¶
type Option func(*Error)
Option customises an E() value.
func WithMetadata ¶
WithMetadata merges a whole map into Meta.