errors

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallOnNilErr

func CallOnNilErr(err error, f func() error) error

CallOnNilErr calls f if err is nil

func FieldError

func FieldError(field string, msg string) error

FieldError creates an instance of BadFieldError without an index

func FieldErrorWithIndex

func FieldErrorWithIndex(index int, field string, msg string, data ...interface{}) error

FieldErrorWithIndex creates an instance of BadFieldError with an index

func IsReqError

func IsReqError(target error) bool

func WrongFieldValueMsg

func WrongFieldValueMsg(expectedType string, actual interface{}) string

WrongFieldValueMsg generates a message to indicate an unexpected field value type

Types

type BadFieldError

type BadFieldError struct {
	Field string
	Msg   string
	Index int
	Data  interface{}
}

BadFieldError implements error. It describes an error relating to an object and/or field. It outputs the example format: `field:id, msg:some error message about id, index:1`

func BadFieldErrorFromStr

func BadFieldErrorFromStr(str string) *BadFieldError

BadFieldErrorFromStr attempts to convert a string to a BadFieldError. It expects the string to match the BadFieldError error output.

func (*BadFieldError) Error

func (b *BadFieldError) Error() string

func (*BadFieldError) Is

func (b *BadFieldError) Is(target error) bool

type ReqError

type ReqError struct {
	Code     string
	HttpCode int
	Msg      string
	Field    string
}

ReqError describes an error consumable by http services.

func ReqErr

func ReqErr(httpCode int, code, field, msg string) *ReqError

ReqErr creates ReqError It outputs the example format: `msg:'some error message', httpCode:'400', code:'err_mempool, field:'id'`

func ReqErrorFromStr

func ReqErrorFromStr(str string) *ReqError

ReqErrorFromStr attempts to convert a string to a ReqError. It expects the string to match the ReqError#Error output. Never returns an error even on failure.

func (*ReqError) Error

func (s *ReqError) Error() string

func (*ReqError) IsSet

func (s *ReqError) IsSet() bool

IsSet returns true if code, http code and msg fields are set

Jump to

Keyboard shortcuts

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