Documentation
¶
Index ¶
- Variables
- func IsCustomError(err error) bool
- type CustomError
- type Error
- func (e *Error) As(target any) bool
- func (e *Error) Error() string
- func (e *Error) GetDetails() []string
- func (e *Error) GetHTTPCode() int
- func (e *Error) GetMessage() string
- func (e *Error) GetReason() string
- func (e *Error) Is(err error) bool
- func (e *Error) SetHTTPStatus(status int) CustomError
- func (e *Error) SetMsg(s string) CustomError
- func (e *Error) With(args ...string) CustomError
- func (e *Error) Withf(format string, args ...any) CustomError
- type ErrorInfoer
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBadRequest = NewError("ErrBadRequest", "请求参数有误") ErrDB = NewError("ErrStore", "数据发生错误") ErrServer = NewError("ErrServer", "服务器发生错误") ErrJSON = NewError("ErrJSON", "JSON 编解码出错") ErrNotFound = NewError("ErrNotFound", "资源未找到") ErrUsedLogic = NewError("ErrUsedLogic", "使用逻辑错误") ErrLoginLimiter = NewError("ErrLoginLimiter", "触发登录限制") ErrPermissionDenied = NewError("ErrPermissionDenied", "没有该资源的权限") ErrTimeout = NewError("ErrTimeout", "请求超时") ErrTooManyRequests = NewError("ErrTooManyRequests", "请求频率过高") ErrNetworkError = NewError("ErrNetworkError", "网络连接错误") ErrFileUpload = NewError("ErrFileUpload", "文件上传失败") ErrFileTooLarge = NewError("ErrFileTooLarge", "文件大小超出限制") ErrUnsupportedMediaType = NewError("ErrUnsupportedMediaType", "不支持的媒体类型") ErrContentTooLarge = NewError("ErrContentTooLarge", "请求体过大") ErrRateLimit = NewError("ErrRateLimit", "请求频率过高").SetHTTPStatus(429) )
常用错误
View Source
var ( ErrNameOrPasswd = NewError("ErrNameOrPasswd", "用户名或密码错误") ErrCaptchaWrong = NewError("ErrCaptchaWrong", "验证码错误") ErrAccountDisabled = NewError("ErrAccountDisabled", "登录限制") )
业务错误
Functions ¶
func IsCustomError ¶ added in v1.3.4
IsCustomError 是否自定义的错误 需要断言后的类型,建议直接使用 `err.(CustomError)` 语法
Types ¶
type CustomError ¶
type CustomError interface {
error
ErrorInfoer
With(args ...string) CustomError
Withf(format string, args ...any) CustomError
SetMsg(s string) CustomError
SetHTTPStatus(status int) CustomError
}
Click to show internal directories.
Click to hide internal directories.