Documentation
¶
Overview ¶
Package humaproblem makes huma produce problem details: every error huma builds, including request validation, becomes a *problem.Problem, and the OpenAPI document lists the codes clients localize on.
Index ¶
- func Document(api huma.API, registries ...*problem.Registry)
- func FieldErrors(errs []error) []*problem.FieldError
- func Install(opts Options)
- func NewError(status int, msg string, errs ...error) huma.StatusError
- func Report(fn func(ctx context.Context, p *problem.Problem)) huma.Transformer
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Document ¶
Document lists every code the API can return in api's OpenAPI document: on the Problem schema, validation and the registries' types; on FieldError, the shared rules and the registries' types, since a field can fail an application's own check. Call it after registering operations.
func FieldErrors ¶
func FieldErrors(errs []error) []*problem.FieldError
FieldErrors converts huma's error details into field errors. A *problem.FieldError among errs, such as one a Resolver returns, is kept as is; an error that locates no field is skipped.
func Install ¶
func Install(opts Options)
Install makes huma build its errors with NewError. Call it once at startup, before registering operations: huma also reads the error type from it to document error responses.
func NewError ¶
func NewError(status int, msg string, errs ...error) huma.StatusError
NewError converts an error huma reports into a problem. A problem among errs is returned as is, and so is one Options.Map returns for them. A 422 with field details becomes a problem.Validation listing them, each typed with the rule it failed. Anything else is an about:blank problem; for a 5xx its message and errs can hold internals, so they become the cause, for logs, rather than the detail.
Types ¶
type Options ¶
type Options struct {
// Map turns an error a handler returned that is not a problem, such as a
// database's not-found error, into one. It returns nil for an error it does
// not recognize, which becomes a 500. The error becomes the problem's cause.
Map func(error) *problem.Problem
// Debug sends a 5xx problem's cause as its detail. Never set it in production.
Debug bool
}
Options configure Install.