Documentation
¶
Overview ¶
Package problem is the one error shape the API returns: RFC 9457 problem details (the revision of RFC 7807), served as application/problem+json.
A Problem is an error, so a handler returns one; the huma hook in huma.go turns every framework error into the same shape, which is why there is no second error type anywhere in the kernel.
Derived from github.com/septagon-oss/pk-problem (Apache-2.0); see NOTICE.
Index ¶
Constants ¶
const ContentType = "application/problem+json"
ContentType is the media type of a problem response.
Variables ¶
This section is empty.
Functions ¶
func HumaError ¶
func HumaError(status int, message string, errs ...error) huma.StatusError
HumaError is the hook that makes huma speak problem details. Assign it once, where the API is built:
huma.NewError = problem.HumaError
It is a plain function rather than an init() so that the wiring is visible at the call site, like every other wire in this repository.
A 5xx never carries its message to the client: at that point the message is as likely to be a driver string as a sentence. The cause stays reachable through errors.Unwrap for the logger.
Types ¶
type Problem ¶
type Problem struct {
// Type identifies the problem type. "about:blank" means the status code
// says everything there is to say.
Type string `json:"type"`
// Title is the status text: the same for every occurrence of a type.
Title string `json:"title"`
// Status is the HTTP status code.
Status int `json:"status"`
// Detail explains this occurrence.
Detail string `json:"detail,omitempty"`
// Errors carries per-field validation messages, when there are any.
Errors []string `json:"errors,omitempty"`
// Instance identifies this occurrence. kit/httpx sets it to
// "urn:request:<request id>", which is the same id the log line carries, so
// a report of "I got a 500" is one grep away from the reason.
Instance string `json:"instance,omitempty"`
// contains filtered or unexported fields
}
Problem is an RFC 9457 problem details object.
func New ¶
New returns a problem with the standard title for status. A status net/http has no text for still gets a title, because a body with an empty one is not an RFC 9457 problem.
func NotFound ¶
New is the constructor for every status; the two below are the only ones with a name of their own, because they are the two kit/rest answers with often enough that spelling the status at each site would be the thing that goes wrong.
NotFound is 404: no such thing, or none this tenant may see.
func (*Problem) ContentType ¶
ContentType satisfies huma.ContentTypeFilter, so the response is labelled application/problem+json rather than application/json.