errors

package
v0.0.0-...-fa384c1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	New          = errors.New
	Wrap         = errors.Wrap
	Wrapf        = errors.Wrapf
	WithStack    = errors.WithStack
	WithMessage  = errors.WithMessage
	WithMessagef = errors.WithMessagef
)

定义别名

View Source
var (
	ErrBadRequest              = New400Response("请求发生错误")
	ErrInvalidParams           = New400Response("请求参数错误")
	ErrInvalidParent           = New400Response("无效的父级节点")
	ErrNotAllowDeleteWithChild = New400Response("含有子级,不能删除")
	ErrNotAllowDelete          = New400Response("资源不允许删除")
	ErrInvalidUserName         = New400Response("无效的用户名")
	ErrInvalidPassword         = New400Response("无效的密码")
	ErrInvalidUser             = New400Response("无效的用户")
	ErrUserDisable             = New400Response("用户被禁用,请联系管理员")

	ErrNoPerm          = NewResponse(401, "无访问权限", 401)
	ErrInvalidToken    = NewResponse(9999, "令牌失效", 406)
	ErrTimeOutToken    = NewResponse(10000, "令牌已过期", 406)
	ErrNotFound        = NewResponse(404, "资源不存在", 404)
	ErrMethodNotAllow  = NewResponse(405, "方法不被允许", 405)
	ErrTooManyRequests = NewResponse(429, "请求过于频繁", 429)
	ErrInternalServer  = NewResponse(500, "服务器发生错误", 500)
)

定义错误

Functions

func New400Response

func New400Response(msg string) error

New400Response 创建错误码为400的响应错误

func New500Response

func New500Response(msg string) error

New500Response 创建错误码为500的响应错误

func NewResponse

func NewResponse(code int, msg string, status ...int) error

NewResponse 创建响应错误

func ValidateError

func ValidateError() gin.HandlerFunc

错误处理

func Wrap400Response

func Wrap400Response(err error, msg ...string) error

Wrap400Response 包装错误码为400的响应错误

func Wrap500Response

func Wrap500Response(err error, msg ...string) error

Wrap500Response 包装错误码为500的响应错误

func WrapResponse

func WrapResponse(err error, code int, msg string, status ...int) error

WrapResponse 包装响应错误

Types

type AppErrorHandler

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

func NewErrorHandler

func NewErrorHandler(uni *ut.UniversalTranslator, trans ut.Translator, validate *validator.Validate) *AppErrorHandler

func (*AppErrorHandler) HandleErrors

func (h *AppErrorHandler) HandleErrors(c *gin.Context)

type ResponseError

type ResponseError struct {
	Code    int    // 错误码
	Message string // 错误消息
	Status  int    // 响应状态码
	ERR     error  // 响应错误
}

ResponseError 定义响应错误

func UnWrapResponse

func UnWrapResponse(err error) *ResponseError

UnWrapResponse 解包响应错误

func (*ResponseError) Error

func (r *ResponseError) Error() string

Jump to

Keyboard shortcuts

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