errmodel

package
v0.99.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 3 Imported by: 0

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

func DefaultParam(code Code) string

DefaultParam is the catalog's field name for a validation code, if any.

func Describe

func Describe(code Code) (status int, message string, ok bool)

Describe reports a code's catalog status and message.

Types

type Code

type Code string

Code is a stable, snake_case wire error code.

func Codes

func Codes() []Code

Codes lists every catalogued code, sorted.

func Define

func Define(code string, status int, message string) Code

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

func DefineParam(code string, status int, param, message string) Code

DefineParam is Define for a validation code that always concerns one request field: the param is filled in when an Error carries none.

func (Code) String

func (c Code) String() string

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 As

func As(err error) *Error

As returns the *Error in err's chain, or nil.

func E

func E(code Code, opts ...Option) *Error

E builds an Error for a catalogued code (status from the catalog; an uncatalogued code is a 500).

func Recode

func Recode(err error, code Code, opts ...Option) *Error

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) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

Is matches any *Error with the same Code, so a sentinel var, a fresh E() and a wrapped copy are all one identity.

func (*Error) Message

func (e *Error) Message() string

Message is the catalog's human-readable message for the code.

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Option

type Option func(*Error)

Option customises an E() value.

func WithCause

func WithCause(cause error) Option

func WithMeta

func WithMeta(key string, value any) Option

func WithMetadata

func WithMetadata(m map[string]any) Option

WithMetadata merges a whole map into Meta.

func WithParam

func WithParam(param string) Option

func WithStatus

func WithStatus(status int) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL