errors

package
v1.14.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 30

Documentation

Index

Constants

View Source
const (
	// Defined by RFC7235 and RFC6750.
	AuthenticateHeader = "WWW-Authenticate"
)

Variables

This section is empty.

Functions

func HandleError

func HandleError(w http.ResponseWriter, r *http.Request, err error)

HandleError is the top level error handler that should be called from all path handlers on error.

func IsAccessDenied

func IsAccessDenied(err error) bool

IsAccessDenied checks if the error is as described.

func IsBadRequest

func IsBadRequest(err error) bool

IsBadRequest checks if the error is as described.

func IsConflict

func IsConflict(err error) bool

IsConflict checks if the error is as described.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden checks if the error is as described.

func IsHTTPNotFound

func IsHTTPNotFound(err error) bool

IsHTTPNotFound checks if the error is as described.

func IsMethodNotAllowed

func IsMethodNotAllowed(err error) bool

IsMethodNotAllowed checks if the error is as described.

func IsRequestEntityTooLarge

func IsRequestEntityTooLarge(err error) bool

IsRequestEntityTooLarge checks if the error is as described.

func IsUnprocessableContent

func IsUnprocessableContent(err error) bool

IsUnprocessableContent checks if the error is as described.

func PropagateError

func PropagateError(r *http.Response, response any) error

PropagateError provides a response type agnostic way of extracting a human readable error from an API. NOTE: the *WithResponse APIs will have read and closed the body already and decoded the JSON error. We just need to get at it, which is tricky!

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error wraps ErrRequest with more contextual information that is used to propagate and create suitable responses.

func AccessDenied

func AccessDenied(r *http.Request, a ...any) *Error

AccessDenied replaces OAuth2AccessDenied. It must be provided with the current host and that must implement the oidc protected resource metadata endpoint (RFC9728).

func FromOpenAPIError added in v1.12.0

func FromOpenAPIError(code int, header http.Header, err *openapi.Error) *Error

FromOpenAPIError allows propagation across API calls.

func HTTPConflict

func HTTPConflict() *Error

HTTPConflict is raised when a request conflicts with another resource.

func HTTPForbidden

func HTTPForbidden(a ...any) *Error

HTTPForbidden is raised when a user isn't permitted to do something by RBAC.

func HTTPMethodNotAllowed

func HTTPMethodNotAllowed() *Error

HTTPMethodNotAllowed is raised when the method is not supported.

func HTTPNotFound

func HTTPNotFound() *Error

HTTPNotFound is raised when the requested resource doesn't exist.

func HTTPRequestEntityTooLarge added in v1.11.0

func HTTPRequestEntityTooLarge(a ...any) *Error

HTTPRequestEntityTooLarge is raised when the request body is too large and overlows internal size limits.

func HTTPUnprocessableContent added in v1.13.0

func HTTPUnprocessableContent(a ...any) *Error

HTTPUnprocessableContent is used when everything is syntactically correct but semantically makes no sense.

func OAuth2AccessDenied

func OAuth2AccessDenied(a ...any) *Error

OAuth2AccessDenied tells the client the authentication failed e.g. username/password are wrong, or a token has expired and needs reauthentication.

func OAuth2InvalidRequest

func OAuth2InvalidRequest(a ...any) *Error

OAuth2InvalidRequest indicates a client error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements Go 1.13 errors.

func (*Error) WithError

func (e *Error) WithError(err error) *Error

WithError augments the error with an error from a library.

func (*Error) WithValues

func (e *Error) WithValues(values ...any) *Error

WithValues augments the error with a set of K/V pairs. Values should not use the "error" key as that's implicitly defined by WithError and could collide.

func (*Error) Write

func (e *Error) Write(w http.ResponseWriter, r *http.Request)

Write returns the error code and description to the client.

type WWWAuthenticateHeader

type WWWAuthenticateHeader struct {
	// contains filtered or unexported fields
}

WWWAuthenticateHeader handles encoding of WWW-Authenticate headers.

func NewWWWAuthenticateHeader

func NewWWWAuthenticateHeader() *WWWAuthenticateHeader

NewWWWAuthenticateHeader create a new empty WWW-Authenticate header.

func (*WWWAuthenticateHeader) AddField

func (w *WWWAuthenticateHeader) AddField(challenge, key, value string)

AddField adds a key value field to a chanllenge type.

func (*WWWAuthenticateHeader) Encode

func (w *WWWAuthenticateHeader) Encode() string

Encode turns the header into a string ready for the wire. It ensures deterministic output.

Jump to

Keyboard shortcuts

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