xerr

package
v0.0.0-...-2beabf4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = New(404, "NotFound", "not found")
	ErrUnauthorized = New(401, "Unauthorized", "unauthorized")
	ErrForbidden    = New(403, "Forbidden", "forbidden")
)

定义错误

Functions

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

ErrorHandler customize echo's HTTP error handler.

func RegisterErrorFunc

func RegisterErrorFunc(f ErrorFunc)

Types

type Error

type Error struct {

	// 错误代码,为英文字符串,前端可用此判断大的错误类型。
	Key string `json:"error"`
	// 错误消息,为详细错误描述,前端可选择性的展示此字段。
	Message any `json:"message,omitempty"`
	// contains filtered or unexported fields
}

Error 对外输出的错误格式

func New

func New(code int, key string, msg any) *Error

New 新建一个 Error 对象

func Newf

func Newf(code int, key string, format string, a ...interface{}) *Error

Newf 新建一个带格式的 Error

func (*Error) Error

func (e *Error) Error() string

Error makes it compatible with `error` interface.

type ErrorFunc

type ErrorFunc func(err error) (ok bool, code int, key string, msg string)

Jump to

Keyboard shortcuts

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