apperr

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 2 Imported by: 0

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

View Source
const (
	TitleBadRequest    = "Bad request"
	TitleUnauthorized  = "Unauthorized"
	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

func MultiOf

func MultiOf(errs ...*T) error

MultiOf carries several typed errors in one document (the reference's multi-violation 422s, e.g. KEY_NOT_ALLOWED and KEY_TOO_SHORT side by side): the first error, with the rest riding as siblings. Every carried error shares the first one's status and title.

Types

type Source

type Source struct {
	Pointer   string
	Parameter string
	Header    string
}

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

func BadRequest(detail string) *T

BadRequest is a 400 without a code (typed-params style).

func BadRequestParameter added in v0.0.5

func BadRequestParameter(detail, parameter string) *T

BadRequestParameter is a 400 pointing at a query parameter.

func BadRequestSource

func BadRequestSource(detail, pointer string) *T

BadRequestSource is a 400 with a source pointer.

func Conflict

func Conflict(detail string) *T

Conflict is a 409.

func Forbidden

func Forbidden(code, detail string) *T

Forbidden builds a 403 with a code (LICENSE_BANNED, USER_BANNED, ...).

func ForbiddenIndex

func ForbiddenIndex(detail, pointer string) *T

ForbiddenIndex is the codeless indexed-pointer 403 of the detach guards ("cannot detach user '<uuid>' (…)").

func ForbiddenReason

func ForbiddenReason(reason string) *T

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 From

func From(err error) *T

From extracts a *T, replacing anything else with the 500.

func Internal

func Internal() *T

Internal is the 500.

func NotFound

func NotFound(resource, id string) *T

NotFound is a record-not-found 404: "The requested <resource> '<id>' was not found".

func NotFoundDefault

func NotFoundDefault() *T

NotFoundDefault is the endpoint-not-found 404.

func NotFoundModel added in v0.0.5

func NotFoundModel(resource string) *T

NotFoundModel is a record-not-found 404 without an id ("The requested <resource> was not found"), e.g. a missing association.

func TokenUnauthorized

func TokenUnauthorized(code, detail string) *T

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

func Unauthorized(code, detail string) *T

Unauthorized builds a 401: code with its default or given detail, and the authentication docs topic.

func UnauthorizedSource

func UnauthorizedSource(code, detail, header, pointer string) *T

UnauthorizedSource is a 401 with a source header (password flow) or a body pointer (the OTP errors).

func Unprocessable

func Unprocessable(code, detail, pointer string) *T

Unprocessable builds a 422 (validation-style errors: code, detail, pointer) with the "Unprocessable resource" title the reference's render_unprocessable_resource emits.

func UnprocessableNoCode

func UnprocessableNoCode(detail, pointer string) *T

UnprocessableNoCode is the codeless 422 of the detach guards ("cannot detach entitlement '<uuid>' (…)", title "Unprocessable entity").

func Validation

func Validation(code, detail, pointer, about string) *T

Validation builds a model-validation 422 ("Unprocessable resource", with code, pointer and the docs link of the attribute or relationship the violation points at).

func (*T) Error

func (t *T) Error() string

Error implements error.

func (*T) Siblings

func (t *T) Siblings() []*T

Siblings answers the additional errors carried alongside this one.

Jump to

Keyboard shortcuts

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