errors

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func As

func As(err error, target any) bool

As finds the first error in err's chain that matches target, and if so, sets

func CreateErrorFn added in v0.0.5

func CreateErrorFn(status int) func(msgs ...any) *Error

func Is

func Is(err, target error) bool

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

Types

type Error

type Error struct {
	Status  int    `json:"-"`
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
	Detail  string `json:"detail,omitempty"`
	// contains filtered or unexported fields
}

Error is error object.

func From

func From(err error) *Error

From is constructor to create error object.

func GetErrorByStatus

func GetErrorByStatus(status int, err error) *Error

func New

func New(message string, extras ...string) *Error

New creates new error object. Example: errors.New("Login failed", "LOGIN_FAILED", "Invalid username or password")

message: error message
extras: error detail and error code

func (*Error) Error

func (e *Error) Error() string

Error is error interface implementation.

func (*Error) Format

func (e *Error) Format(f fmt.State, c rune)

Format is error interface implementation.

func (*Error) FormatError

func (e *Error) FormatError(p xerrors.Printer) error

FormatError is error interface implementation.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON is json.Marshaler interface implementation.

func (*Error) Messagef

func (e *Error) Messagef(format string, a ...any) *Error

func (*Error) Trace

func (e *Error) Trace() error

Trace is constructor to wrap error object.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the result of calling the Unwrap method on err.

func (*Error) Wrap

func (e *Error) Wrap(target error) error

Wrap is constructor to wrap error object.

Jump to

Keyboard shortcuts

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