Documentation
¶
Index ¶
- Variables
- func New400ErrResponse(code int, data interface{}, msg string, args ...interface{}) error
- func New400ErrResponseWithField(field string, code int, data interface{}, msg string, args ...interface{}) error
- func New400Response(code int, msg string, args ...interface{}) error
- func New400ResponseWithField(field string, code int, msg string, args ...interface{}) error
- func New500Error(code int, data interface{}) error
- func New500Response(msg string, args ...interface{}) error
- func NewError(code int, err error) error
- func NewErrorMsg(code int, err error, msg string, args ...interface{}) error
- func NewMsg(code int, msg string, args ...interface{}) error
- func NewResError(err error) error
- func NewResErrorMsg(err error, msg string, a ...any) error
- func NewResponse(statusCode, code int, data interface{}, msg string, args ...interface{}) error
- func NewResponseWithField(statusCode int, field string, code int, data interface{}, msg string, ...) error
- func Wrap400Err(err error, code int) error
- func Wrap400ErrResponse(err error, code int, data interface{}, msg string, args ...interface{}) error
- func Wrap400ErrWithField(err error, field string, code int) error
- func Wrap400Response(err error, code int, msg string, args ...interface{}) error
- func Wrap400ResponseWithField(err error, field string, code int, data interface{}, msg string, ...) error
- func Wrap500Response(err error, msg string, args ...interface{}) error
- func WrapField(err error, field string) error
- func WrapResponse(err error, statusCode, code int, data interface{}, msg string, ...) error
- func WrapResponseWithField(err error, statusCode int, field string, code int, data interface{}, ...) error
- type ResponseError
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 Is = errors.Is Unwrap = errors.Unwrap Errorf = errors.Errorf Cause = errors.Cause As = gError.As )
定义别名
View Source
var ( ErrBadRequest = New400Response(400, "请求发生错误") ErrInvalidParent = New400Response(400, "无效的父级节点") ErrNotAllowDeleteWithChild = New400Response(400, "含有子级,不能删除") ErrNotAllowDelete = New400Response(400, "资源不允许删除") ErrInvalidUserName = New400Response(400, "无效的用户名") ErrInvalidPassword = New400Response(400, "无效的密码") ErrInvalidUser = New400Response(400, "无效的用户") ErrUserDisable = New400Response(400, "用户被禁用,请联系管理员") ErrNoPerm = NewResponse(401, 401, nil, "无访问权限") ErrInvalidToken = NewResponse(401, 401, nil, "令牌失效") ErrNotToken = NewResponse(401, 401, nil, "未找到令牌") ErrNotFound = WrapResponseWithField(fmt.Errorf("资源不存在"), 400, "", 100030002, nil, "资源不存在") ErrMethodNotAllow = NewResponse(405, 405, nil, "方法不被允许") ErrTooManyRequests = NewResponse(429, 429, nil, "请求过于频繁") ErrInternalServer = NewResponse(500, 500, nil, "服务器发生错误") )
定义错误
Functions ¶
func New400ErrResponse ¶
New400ErrResponse 创建错误码为400的响应错误
func New400Response ¶
func New400ResponseWithField ¶
func New500Error ¶
func New500Response ¶
New500Response 创建错误码为500的响应错误
func NewResError ¶
func NewResponse ¶
NewResponse 创建响应错误
func NewResponseWithField ¶
func NewResponseWithField(statusCode int, field string, code int, data interface{}, msg string, args ...interface{}) error
NewResponseWithField 创建响应错误包含错误字段
func Wrap400Err ¶
func Wrap400ErrResponse ¶
func Wrap400ErrResponse(err error, code int, data interface{}, msg string, args ...interface{}) error
Wrap400ErrResponse 包装错误码为400的响应错误
func Wrap400Response ¶
Wrap400Response 包装错误码为400的响应错误
func Wrap500Response ¶
Wrap500Response 包装错误码为500的响应错误
Types ¶
type ResponseError ¶
type ResponseError struct {
Code int // 错误码
Message string // 错误消息
StatusCode int // 响应状态码
ERR error // 响应错误
Field string // 错误字段
Data interface{} // 模版数据
}
ResponseError 定义响应错误
func (*ResponseError) Cause ¶
func (r *ResponseError) Cause() error
func (*ResponseError) Error ¶
func (r *ResponseError) Error() string
func (*ResponseError) Unwrap ¶
func (r *ResponseError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.