errors

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotFoundError = NewError(404, "record not found")

Functions

func As

func As(err error, target interface{}) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.

As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.

func IsNotFount

func IsNotFount(err error) bool

func New

func New(msg string) error

func NewNotFoundError

func NewNotFoundError(name string) error

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

func WithMessage

func WithMessage(err error, msg string) error

Types

type Error

type Error interface {
	Code() string
	StatusCode() int
	error
}

func NewError

func NewError(status int, msg string, code ...string) Error

func With

func With(status int, err error, msg string, code ...string) Error

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

func NewErrors

func NewErrors(status int, prefix string, code ...string) *Errors

func (*Errors) Append

func (m *Errors) Append(err error)

func (*Errors) Code

func (m *Errors) Code() string

func (*Errors) Error

func (m *Errors) Error() string

func (*Errors) HasError

func (m *Errors) HasError() bool

func (*Errors) StatusCode

func (m *Errors) StatusCode() int

Jump to

Keyboard shortcuts

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