ucerr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIncorrectUsernamePassword = OAuthError{
	ErrorType: "invalid_grant",
	ErrorDesc: "incorrect username or password",
	Code:      http.StatusBadRequest,
}

ErrIncorrectUsernamePassword indicates a bad username or password.

View Source
var ErrInvalidAuthHeader = OAuthError{
	ErrorType: "invalid_token",
	ErrorDesc: "invalid 'Authorization' header",
	Code:      http.StatusUnauthorized,
}

ErrInvalidAuthHeader indicates a bad HTTP Authorization header in an auth'd request.

View Source
var ErrInvalidAuthorizationCode = OAuthError{
	ErrorType: "invalid_grant",
	ErrorDesc: "invalid code",
	Code:      http.StatusBadRequest,
}

ErrInvalidAuthorizationCode indicates a bad authorization code.

View Source
var ErrInvalidClientSecret = OAuthError{
	ErrorType: "invalid_grant",
	ErrorDesc: "invalid client secret",
	Code:      http.StatusBadRequest,
}

ErrInvalidClientSecret indicates a bad client_secret.

View Source
var ErrInvalidCodeVerifier = OAuthError{
	ErrorType: "invalid_grant",
	ErrorDesc: "invalid code verifier",
	Code:      http.StatusBadRequest,
}

ErrInvalidCodeVerifier indicates a bad code_verifier argument in a Authorization Code w/PKCE login.

Functions

func BaseError added in v0.4.0

func BaseError(err error) error

BaseError returns the bottom of the stack original error

func Combine added in v0.4.0

func Combine(l, r error) error

Combine lets you merge multiple errors and return them all (eg. 2 of 5 in a batch failed) TODO: write some tests, fix up output nicely

func Errorf

func Errorf(temp string, args ...interface{}) error

Errorf is our local version of fmt.Errorf including callsite info

func Friendlyf

func Friendlyf(err error, format string, args ...interface{}) error

Friendlyf wraps an error with a user-friendly message

func New

func New(text string) error

New creates a new ucerr

func NewInvalidClientError

func NewInvalidClientError(err error) error

NewInvalidClientError returns an error signifying a bad client ID.

func NewInvalidTokenError

func NewInvalidTokenError(err error) error

NewInvalidTokenError returns an error signifying a bad token of some kind.

func NewRequestError

func NewRequestError(err error) error

NewRequestError returns a new bad request error.

func NewServerError

func NewServerError(err error) error

NewServerError returns a new internal server error.

func NewUnsupportedGrantError

func NewUnsupportedGrantError(grant string) error

NewUnsupportedGrantError returns a new error signifying an unsupported OAuth `grant_type`.

func NewUnsupportedResponseError

func NewUnsupportedResponseError(responseType string) error

NewUnsupportedResponseError returns a new error signifying an unsupported OAuth `response_type`.

func UserFriendlyMessage

func UserFriendlyMessage(err error) string

UserFriendlyMessage is just a simple wrapper to handle casting error -> ucError

func UserFriendlyStructure added in v0.3.0

func UserFriendlyStructure(err error) interface{}

UserFriendlyStructure exposes the structured error data if error is a ucError

func Wrap

func Wrap(err error, opts ...Option) error

Wrap wraps an existing error with an additional level of the callstack

func WrapWithFriendlyStructure added in v0.3.0

func WrapWithFriendlyStructure(err error, structure interface{}) error

WrapWithFriendlyStructure wraps an error with a structured error

Types

type OAuthError

type OAuthError struct {
	ErrorType string `json:"error"`
	ErrorDesc string `json:"error_description,omitempty"`
	Code      int    `json:"-"`
	// contains filtered or unexported fields
}

OAuthError implements error but can be marshalled to JSON to make an OAuth/OIDC-compliant error. TODO: Should this be a private type like `ucError`?

func (OAuthError) Error

func (o OAuthError) Error() string

Error implements interface `error` for type `OAuthError`

func (OAuthError) Unwrap

func (o OAuthError) Unwrap() error

Unwrap implements errors.Unwrap for errors.Is & errors.As

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option defines a way to modify ucerr behavior

func ExtraSkip

func ExtraSkip() Option

ExtraSkip tells Wrap to skip an extra frame in the stack when wrapping an error This allows calls like uchttp.Error() and jsonapi.MarshalError() to call Wrap() and capture the stack frame that actually logged the error (since we rarely call eg, jsonapi.MarshalError(ucerr.Wrap(err)), we lose useful debugging data)

type UCError

type UCError interface {
	Error() string // include this so UCError implements Error for erroras linter
	Friendly() string
	FriendlyStructure() interface{}
}

UCError lets us figure out if this is a wrapped error

Jump to

Keyboard shortcuts

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