xerror

package
v0.2.52 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDone done
	ErrDone                = errors.New("DONE")
	ErrBadRequest          = New(400, http.StatusText(400))
	ErrUnauthorized        = New(401, http.StatusText(401))
	ErrForbidden           = New(403, http.StatusText(403))
	ErrNotFound            = New(404, http.StatusText(404))
	ErrMethodNotAllowed    = New(405, http.StatusText(405))
	ErrTimeout             = New(408, http.StatusText(408))
	ErrConflict            = New(409, http.StatusText(409))
	ErrInternalServerError = New(500, http.StatusText(500))
	Debug                  bool
)
View Source
var (
	UnWrap = errors.Unwrap
	Is     = errors.Is
	As     = func(err error, target interface{}) bool {
		if target == nil {
			return false
		}

		val := reflect.ValueOf(target)
		typ := val.Type()

		if typ.Kind() != reflect.Ptr || val.IsNil() {
			return false
		}

		if e := typ.Elem(); e.Kind() != reflect.Interface && !typ.Implements(errorType) {
			return false
		}

		targetType := typ.Elem()
		for err != nil {
			if reflect.TypeOf(err).AssignableTo(targetType) {
				val.Elem().Set(reflect.ValueOf(err))
				return true
			}
			if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) {
				return true
			}
			err = UnWrap(err)
		}
		return false
	}
)

ext from errors

Functions

func Exit added in v0.1.27

func Exit(err error)

func ExitErr added in v0.2.18

func ExitErr(_ interface{}, err error)

ExitErr

func ExitF added in v0.2.47

func ExitF(err error, msg string, args ...interface{})

ExitF

func New added in v0.1.32

func New(code int, Msg string) interface {
	Wrap(error) error
	Code() int
}

func Panic

func Panic(err error)

func PanicBytes added in v0.2.39

func PanicBytes(d1 []byte, err error) []byte

func PanicErr

func PanicErr(d1 interface{}, err error) interface{}

PanicErr

func PanicF added in v0.2.52

func PanicF(err error, msg string, args ...interface{})

func PanicFile added in v0.2.52

func PanicFile(d1 *os.File, err error) *os.File

func PanicResponse added in v0.2.52

func PanicResponse(d1 *http.Response, err error) *http.Response

func PanicStr added in v0.2.39

func PanicStr(d1 string, err error) string

func Resp

func Resp(f func(err XErr))

Resp

func RespErr

func RespErr(err *error)

func Wrap

func Wrap(err error) error

func WrapF added in v0.2.52

func WrapF(err error, msg string, args ...interface{}) error

Types

type Frame added in v0.2.52

type Frame uintptr

type XErr added in v0.2.10

type XErr interface {
	error
	As(err interface{}) bool
	Is(err error) bool
	Unwrap() error
	Wrap(err error) error
	Code() int
}

Jump to

Keyboard shortcuts

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