xerr

package
v0.0.0-...-d6b644b Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = New(404, "NotFound", "没有找到相应记录")
	ErrAuthFailed   = New(401, "AuthFailed", "登录失败")
	ErrUnauthorized = New(401, "Unauthorized", "本接口只有登录用户才能调用")
	ErrForbidden    = New(403, "Forbidden", "权限不足")
	ErrDuplicate    = New(400, "Duplicate", "已有相同业务数据存在")
)

定义错误

Functions

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

ErrorHandler customize echo's HTTP error handler.

func IsErrDuplicate

func IsErrDuplicate(err error) bool

IsErrDuplicate 是否为本模块的 ErrDuplicate 错误

Types

type Error

type Error struct {

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

Error 对外输出的错误格式

func New

func New(code int, key string, msg string) *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.

Jump to

Keyboard shortcuts

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