Documentation
¶
Index ¶
- Constants
- func HandleError(w http.ResponseWriter, r *http.Request, err error)
- func IsAccessDenied(err error) bool
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsHTTPNotFound(err error) bool
- func IsMethodNotAllowed(err error) bool
- func IsRequestEntityTooLarge(err error) bool
- func IsUnprocessableContent(err error) bool
- func PropagateError(r *http.Response, response any) error
- type Error
- func AccessDenied(r *http.Request, a ...any) *Error
- func FromOpenAPIError(code int, header http.Header, err *openapi.Error) *Error
- func HTTPConflict() *Error
- func HTTPForbidden(a ...any) *Error
- func HTTPMethodNotAllowed() *Error
- func HTTPNotFound() *Error
- func HTTPRequestEntityTooLarge(a ...any) *Error
- func HTTPUnprocessableContent(a ...any) *Error
- func OAuth2AccessDenied(a ...any) *Error
- func OAuth2InvalidRequest(a ...any) *Error
- type WWWAuthenticateHeader
Constants ¶
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 ¶
IsAccessDenied checks if the error is as described.
func IsBadRequest ¶
IsBadRequest checks if the error is as described.
func IsForbidden ¶
IsForbidden checks if the error is as described.
func IsHTTPNotFound ¶
IsHTTPNotFound checks if the error is as described.
func IsMethodNotAllowed ¶
IsMethodNotAllowed checks if the error is as described.
func IsRequestEntityTooLarge ¶
IsRequestEntityTooLarge checks if the error is as described.
func IsUnprocessableContent ¶
IsUnprocessableContent checks if the error is as described.
func PropagateError ¶
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 ¶
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
FromOpenAPIError allows propagation across API calls.
func HTTPConflict ¶
func HTTPConflict() *Error
HTTPConflict is raised when a request conflicts with another resource.
func HTTPForbidden ¶
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
HTTPRequestEntityTooLarge is raised when the request body is too large and overlows internal size limits.
func HTTPUnprocessableContent ¶ added in v1.13.0
HTTPUnprocessableContent is used when everything is syntactically correct but semantically makes no sense.
func OAuth2AccessDenied ¶
OAuth2AccessDenied tells the client the authentication failed e.g. username/password are wrong, or a token has expired and needs reauthentication.
func OAuth2InvalidRequest ¶
OAuth2InvalidRequest indicates a client error.
func (*Error) WithValues ¶
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.
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.