errors

package
v0.31.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Index

Constants

View Source
const (
	CodeNotFound = iota + 1
	CodeDuplicated
	CodeLimit
	CodeInvalid
	CodePayment
	CodeUnauthorized
	CodeForbidden
	CodeStore
	CodeNotImplemented
	CodeConflict
	CodeLocked
	CodeInternal
	CodeUnprocessable
	CodeTooManyRequests
)

The kinds of failure an Error's Code names. Every layer whose errors can reach the API uses these, so a kind answers with the same HTTP status whichever layer raised it.

Variables

This section is empty.

Functions

func As added in v0.13.0

func As(err error, target any) bool

As wraps errors.As. Check errors.As for more information.

func HTTPStatus added in v0.31.0

func HTTPStatus(code int) int

HTTPStatus returns the status the API answers an error of code with. CodeStore, CodeInternal and a code outside the kinds above answer 500.

func Is added in v0.13.0

func Is(err, target error) bool

Is wraps errors.Is. Check errors.Is for more information.

func New

func New(message, layer string, code int) error

New creates a new Error.

func WithData

func WithData(parent error, data Data) error

WithData returns the Error in parent's chain with data as its Data. A nil parent returns nil, and a parent with no Error in its chain comes back unchanged.

func Wrap

func Wrap(err error, next error) error

Wrap wraps an error with another error.

It is a interface for errors.Join. Check errors.Join for more information.

Types

type Data

type Data any

Data is a custom type to carry error's metadata. It can be any data type, but a struct is recommended due its fine control on JSON marshalling for each field.

type Error

type Error struct {
	Message string
	Layer   string
	Code    int
	Data    Data
}

Error is a custom error that carry attributes to specify error's message, resource, layer, code and data.

func (Error) Error

func (e Error) Error() string

func (Error) Is added in v0.27.0

func (e Error) Is(target error) bool

Is ignores Data so that WithData copies still match their sentinel.

type InvalidFields added in v0.31.0

type InvalidFields struct {
	Fields map[string]string `json:"fields"`
}

InvalidFields is the Data of an error that names the request fields at fault and why, so a client can mark each one rather than show one message for the whole request.

Jump to

Keyboard shortcuts

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