errors

package
v0.1.71 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 4 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequest is raised for all handler errors.
	ErrRequest = errors.New("request error")
)

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 IsHTTPNotFound

func IsHTTPNotFound(err error) bool

IsHTTPNotFound interrogates the error type.

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 HTTPConflict

func HTTPConflict() *Error

HTTPConflict is raised when a request conflicts with another resource.

func HTTPForbidden

func HTTPForbidden(description string) *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 OAuth2AccessDenied

func OAuth2AccessDenied(description string) *Error

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

func OAuth2InvalidClient

func OAuth2InvalidClient(description string) *Error

OAuth2InvalidClient is raised when the client ID is not known.

func OAuth2InvalidGrant

func OAuth2InvalidGrant(description string) *Error

OAuth2InvalidGrant is raised when the requested grant is unknown.

func OAuth2InvalidRequest

func OAuth2InvalidRequest(description string) *Error

OAuth2InvalidRequest indicates a client error.

func OAuth2InvalidScope

func OAuth2InvalidScope(description string) *Error

OAuth2InvalidScope tells the client it doesn't have the necessary scope to access the resource.

func OAuth2ServerError

func OAuth2ServerError(description string) *Error

OAuth2ServerError tells the client we are at fault, this should never be seen in production. If so then our testing needs to improve.

func OAuth2UnauthorizedClient

func OAuth2UnauthorizedClient(description string) *Error

OAuth2UnauthorizedClient indicates the client is not authorized to perform the requested operation.

func OAuth2UnsupportedGrantType

func OAuth2UnsupportedGrantType(description string) *Error

OAuth2UnsupportedGrantType is raised when the requested grant is not supported.

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 ...interface{}) *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 OAuth2Error

type OAuth2Error struct {
	// Error defines the error type.
	Error OAuth2ErrorType `json:"error"`
	// Description is a verbose description of the error.  This should be
	// informative to the end user, not a bunch of debugging nonsense.  We
	// keep that in telemetry dats.
	//nolint:tagliatelle
	Description string `json:"error_description"`
}

OAuth2Error is the type sent on the wire on error.

type OAuth2ErrorType

type OAuth2ErrorType string

OAuth2ErrorType defines our core error type based on oauth2.

const (
	AccessDenied            OAuth2ErrorType = "access_denied"
	Conflict                OAuth2ErrorType = "conflict"
	Forbidden               OAuth2ErrorType = "forbidden"
	InvalidClient           OAuth2ErrorType = "invalid_client"
	InvalidGrant            OAuth2ErrorType = "invalid_grant"
	InvalidRequest          OAuth2ErrorType = "invalid_request"
	InvalidScope            OAuth2ErrorType = "invalid_scope"
	MethodNotAllowed        OAuth2ErrorType = "method_not_allowed"
	NotFound                OAuth2ErrorType = "not_found"
	ServerError             OAuth2ErrorType = "server_error"
	TemporarilyUnavailable  OAuth2ErrorType = "temporarily_unavailable"
	UnauthorizedClient      OAuth2ErrorType = "unauthorized_client"
	UnsupportedGrantType    OAuth2ErrorType = "unsupported_grant_type"
	UnsupportedMediaType    OAuth2ErrorType = "unsupported_media_type"
	UnsupportedResponseType OAuth2ErrorType = "unsupported_response_type"
)

Jump to

Keyboard shortcuts

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