Documentation
¶
Index ¶
- func As(err error, target interface{}) bool
- func ErrBasic() int
- func ErrDb() int
- func Is(err, target error) bool
- func IsCode(err error, code int) bool
- func New(format string, args ...any) error
- func ParseCode(err error) *withCode
- func SetDefault(httpCode, businessCode int, message string)
- func SetServiceCode(code int)
- func UmWrap(err error) error
- func WithCode(err error, businessCode int, options ...Option) error
- func Wrap(err error, format string, args ...any) error
- type ErrCode
- func NewAlreadyExists(businessCode int, message string) ErrCode
- func NewBadRequest(businessCode int, message string) ErrCode
- func NewCode(httpCode, businessCode int, message string) ErrCode
- func NewConflict(businessCode int, message string) ErrCode
- func NewForbidden(businessCode int, message string) ErrCode
- func NewGenerateNameConflict(businessCode int, message string) ErrCode
- func NewGone(businessCode int, message string) ErrCode
- func NewInternalError(businessCode int, message string) ErrCode
- func NewMethodNotSupported(businessCode int, message string) ErrCode
- func NewNotFound(businessCode int, message string) ErrCode
- func NewOK(businessCode int, message string) ErrCode
- func NewRequestEntityTooLargeError(businessCode int, message string) ErrCode
- func NewServiceUnavailable(businessCode int, message string) ErrCode
- func NewTimeoutError(businessCode int, message string) ErrCode
- func NewTooManyRequests(businessCode int, message string) ErrCode
- func NewTooManyRequestsError(businessCode int, message string) ErrCode
- func NewUnauthorized(businessCode int, message string) ErrCode
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseCode ¶
func ParseCode(err error) *withCode
ParseCode 将错误解析为错误码错误 若err不是错误码错误,则包裹传递错误,其他信息为默认错误码信息 若err为错误码错误,将其转换,将最外层错误信息作为最终错误信息返回 若想得到原始的错误码错误,可以使用As方法
func SetDefault ¶
SetDefault 设置默认错误码 当错误码匹配失败时,提供的备选方案,已内置默认错误码, 它的HTTP码为200,业务码和信息均为零值
Types ¶
type ErrCode ¶
type ErrCode struct { // HttpCode 该错误码建议的HTTP响应码 HttpCode int `json:"httpCode,omitempty"` // BusinessCode 该错误码对应的业务码 // +optional BusinessCode int `json:"businessCode,omitempty"` // Message 该错误码对应的错误信息 // +optional Message string `json:"message,omitempty"` }
ErrCode 产生error所包含的错误码信息 支持http错误码、业务错误码 可通过下方快捷函数快速创建指定http码的错误码
func NewAlreadyExists ¶
func NewBadRequest ¶
func NewConflict ¶
func NewForbidden ¶
func NewGenerateNameConflict ¶
func NewInternalError ¶
func NewMethodNotSupported ¶
func NewNotFound ¶
func NewServiceUnavailable ¶
func NewTimeoutError ¶
func NewTooManyRequests ¶
func NewTooManyRequestsError ¶
func NewUnauthorized ¶
Click to show internal directories.
Click to hide internal directories.