Package problem
Overview
Package problem writes an error as an RFC 9457 problem details response, mapping the errors an operation declares to statuses and problem types.
Index
Functions
For source
func For(err error, fallback rfc9110.Status, statuses ...ErrorStatus) rfc9457.ProblemFor returns the problem for err. It uses the first ErrorStatus whose Err matches err, with err's message as the detail. Otherwise it uses fallback: with err's message as the detail for a 4xx, such as a 400 for a request that doesn't parse, or with no detail for a 5xx, so internal errors never reach the client.
Write source
func Write(w http.ResponseWriter, r *http.Request, err error, fallback rfc9110.Status, statuses ...ErrorStatus)Write responds to r with the problem for err, as For builds it, and attaches err to the request log with httplog.SetError.
WriteProblem source
func WriteProblem(w http.ResponseWriter, r *http.Request, p rfc9457.Problem)WriteProblem responds with p. If p can't be marshalled, such as when an extension's value can't be, it responds with a plain 500 instead.
Types
ErrorStatus source
type ErrorStatus struct {
// Err is the declared error, such as ErrUserNotFound.
Err error
// Status is the response status, with any header fields it needs.
Status rfc9110.Status
// Type is the problem type. The zero Type is "about:blank".
Type rfc9457.Type
}ErrorStatus maps an error that an operation declares to the status and problem type a handler responds with. Errors are matched with errors.Is.