errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Is     = errors.Is
	As     = errors.As
	New    = errors.New
	Errorf = fmt.Errorf
)
View Source
var (
	NotFound      = Error{Code: "not_found", Status: http.StatusNotFound}
	Conflict      = Error{Code: "conflict", Status: http.StatusConflict}
	Forbidden     = Error{Code: "forbidden", Status: http.StatusForbidden}
	Throttled     = Error{Code: "throttled", Status: http.StatusTooManyRequests}
	MissingAuth   = Error{Code: "missing_auth", Status: http.StatusUnauthorized}
	Unsupported   = Error{Code: "unsupported", Status: http.StatusUnprocessableEntity}
	InvalidInput  = Error{Code: "invalid_input", Status: http.StatusBadRequest}
	InternalIssue = Error{Code: "internal_issue", Status: http.StatusInternalServerError}
)

Functions

func OneOf

func OneOf(err error, others []error) bool

OneOf checks (in-order) if err is one of the given errors.

Types

type Error

type Error struct {
	Code      string         `json:"code"`
	Cause     error          `json:"cause"`
	Status    int            `json:"status"`
	Attribs   map[string]any `json:"attribs"`
	DebugHint string         `json:"debug_hint"`
}

Error represents an error value with all the relevant context.

func E

func E(err error) Error

E converts any given error to the Error type. Unknown are converted to ErrInternal.

func (Error) CausedBy

func (err Error) CausedBy(e error) Error

CausedBy returns a clone of the error with `e` set as the cause.

func (Error) Coded

func (err Error) Coded(code string, attribs ...map[string]any) Error

Coded returns a clone of the original error with the given code.

func (Error) Error

func (err Error) Error() string

Error represents technical description of the error.

func (Error) Hintf

func (err Error) Hintf(format string, args ...any) Error

Hintf returns a clone of the error with a debug hint.

func (Error) Is

func (err Error) Is(other error) bool

Is checks if 'other' is of type Error and has the same code. See https://blog.golang.org/go1.13-errors.

Jump to

Keyboard shortcuts

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