Documentation
¶
Overview ¶
Package apperr is the typed application error: everything a handler needs to render a Keygen error document (status, title, detail, code, source pointer/parameter/header, docs link).
Index ¶
- Constants
- func MultiOf(errs ...*T) error
- type Source
- type T
- func BadRequest(detail string) *T
- func BadRequestParameter(detail, parameter string) *T
- func BadRequestSource(detail, pointer string) *T
- func Conflict(detail string) *T
- func Forbidden(code, detail string) *T
- func ForbiddenIndex(detail, pointer string) *T
- func ForbiddenReason(reason string) *T
- func From(err error) *T
- func Internal() *T
- func NotFound(resource, id string) *T
- func NotFoundDefault() *T
- func NotFoundModel(resource string) *T
- func TokenUnauthorized(code, detail string) *T
- func Unauthorized(code, detail string) *T
- func UnauthorizedSource(code, detail, header, pointer string) *T
- func Unprocessable(code, detail, pointer string) *T
- func UnprocessableNoCode(detail, pointer string) *T
- func Validation(code, detail, pointer, about string) *T
Constants ¶
const ( TitleBadRequest = "Bad request" TitleForbidden = "Access denied" TitleNotFound = "Not found" TitleConflict = "Conflict" TitleUnprocessable = "Unprocessable entity" // TitleUnprocessableResource is the model-validation 422 title // ("Unprocessable resource", with code and pointer). TitleUnprocessableResource = "Unprocessable resource" TitleTooManyRequests = "Too many requests" TitleInternalServerError = "Internal server error" )
The canonical titles.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Source ¶
Source points at what caused the error: a JSON pointer into the request body, a query parameter, or a request header.
type T ¶
type T struct {
Status int
Title string
Detail string
Code string
Source Source
// About is the docs topic after "/docs/api/", e.g.
// "authentication/#token-authentication"; empty for none.
About string
// contains filtered or unexported fields
}
T is a typed application error. About is a docs topic resolved against the installation's docs host at render time (the reference builds https://<keygen-domain>/docs/api/... links).
func BadRequest ¶
BadRequest is a 400 without a code (typed-params style).
func BadRequestParameter ¶ added in v0.0.5
BadRequestParameter is a 400 pointing at a query parameter.
func BadRequestSource ¶
BadRequestSource is a 400 with a source pointer.
func ForbiddenIndex ¶
ForbiddenIndex is the codeless indexed-pointer 403 of the detach guards ("cannot detach user '<uuid>' (…)").
func ForbiddenReason ¶
ForbiddenReason is the permission-denied 403: the default detail with the policy's inline reason appended, e.g. "(ensure the token or license is allowed to access all resources)".
func NotFound ¶
NotFound is a record-not-found 404: "The requested <resource> '<id>' was not found".
func NotFoundModel ¶ added in v0.0.5
NotFoundModel is a record-not-found 404 without an id ("The requested <resource> was not found"), e.g. a missing association.
func TokenUnauthorized ¶
TokenUnauthorized is a 401 whose docs link targets token authentication specifically (the bare TOKEN_MISSING keeps the generic authentication link, like the reference).
func Unauthorized ¶
Unauthorized builds a 401: code with its default or given detail, and the authentication docs topic.
func UnauthorizedSource ¶
UnauthorizedSource is a 401 with a source header (password flow) or a body pointer (the OTP errors).
func Unprocessable ¶
Unprocessable builds a 422 (validation-style errors: code, detail, pointer) with the "Unprocessable resource" title the reference's render_unprocessable_resource emits.
func UnprocessableNoCode ¶
UnprocessableNoCode is the codeless 422 of the detach guards ("cannot detach entitlement '<uuid>' (…)", title "Unprocessable entity").
func Validation ¶
Validation builds a model-validation 422 ("Unprocessable resource", with code, pointer and the docs link of the attribute or relationship the violation points at).