error

package
v2.19.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: CC0-1.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func E

func E(args ...interface{}) error

E for creating new errors

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf function

func Match

func Match(errs1, errs2 error) bool

Match errorr Match will match two strings error through a fuzzy matching Need some improvement in fuzzy matching, not all cases is covered

func WithCodes

func WithCodes(codes Codes) error

WithCodes give a safer passing of codes to errors as compiler/linter will check the interface{} implementation

Types

type Codes

type Codes interface {
	ErrorAndCode() (string, int)
	Err() error
}

Codes is interface to define error custom code. It have two function called ErrorAndCode which return string of error and httpcode desired from the error Err will return the error of code itself, so error can be implemented directly in Codes

type Error

type Error struct {
	Err error
	// Codes used for Errs to identify known errors in the application
	// If the error is expected by Errs object, the errors will be shown as listed in Codes
	Code Codes
	// Traces used to add function traces to errors, this is different from context
	// While context is used to add more information about the error, traces is used
	// for easier function tracing purposes without hurting heap too much
	Traces []string
	// Fields is a fields context similar to logrus.Fields
	// Can be used for adding more context to the errors
	Fields Fields
	// Op is operaions of error
	Op Op
	// OpTraces is a trace of operations
	OpTraces []Op
}

Error struct

func (*Error) Error

func (e *Error) Error() string

func (*Error) GetFields

func (e *Error) GetFields() Fields

GetFields return available fields in errors

type Fields

type Fields map[string]interface{}

Fields of error

func (Fields) ToArrayInterface

func (f Fields) ToArrayInterface() []interface{}

ToArrayInterface fields

type Op

type Op string

Op is operation of error

type RequestError

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

func New

func New(err error) *RequestError

func (*RequestError) AppendData

func (re *RequestError) AppendData(key string, data interface{}) *RequestError

func (*RequestError) Error

func (re *RequestError) Error() string

func (*RequestError) GetCode

func (re *RequestError) GetCode() int

func (*RequestError) GetData

func (re *RequestError) GetData() map[string]interface{}

func (*RequestError) GetMessage

func (re *RequestError) GetMessage() string

func (*RequestError) SetCode

func (re *RequestError) SetCode(code int) *RequestError

func (*RequestError) SetMessage

func (re *RequestError) SetMessage(msg string) *RequestError

Jump to

Keyboard shortcuts

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