errors

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLastError added in v0.10.9

func GetLastError(err error) error

GetLastError returns the last error in the error's chain. If there is no next error, returns nil.

func New

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

New creates a new Error.

An Error contains a message, message that will be showed when Error() method is called, a layer, where the error happened and a code, that should be unique in the layer.

func WithData

func WithData(parent error, data Data) error

WithData creates a new Error from other with data. If parent is not from Error type, just return the parameter.

func Wrap

func Wrap(err error, next error) error

Wrap adds an Error to the error's chain. If err is nil, return nil. If next is nil, return err.

Types

type Data

type Data interface{}

type Error

type Error struct {
	// message is the error message.
	Message string `json:"message"`
	// Layer is the error layer.
	Layer string `json:"layer,omitempty"`
	// Code is the error code.
	Code int `json:"code,omitempty"`
	// Data is the error metadata.
	Data Data `json:"data,omitempty"`
	// Next is the next error in the error's chain. next is nil when has no more error in the error's chain.
	Next error `json:"next,omitempty"`
}

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

func (Error) Error

func (e Error) Error() string

Error returns a message aggregating all errors' messages in the chain.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the next error in the error's chain. If there is no next error, returns nil.

Jump to

Keyboard shortcuts

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