Documentation ¶
Index ¶
- Constants
- func As(err error, target any) bool
- func Is(err, target error) bool
- func IsCode[T codeType](err error, code T) bool
- func New(format string, args ...any) error
- func ParseCode(err error) *withCode
- func SetAppCode[T codeType](code T)
- func SetDefault(httpCode, businessCode int, message string)
- func TransferFromError(err error) error
- func UnWrap(err error) error
- func WithCode[T codeType](err error, businessCode T, options ...Option) error
- func WithStack(err error) 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 ¶
View Source
const ( ErrBasic = iota + 1 ErrDb ErrParam ErrRetry ErrServiceInvoke )
Variables ¶
This section is empty.
Functions ¶
func ParseCode ¶ added in v0.3.0
func ParseCode(err error) *withCode
ParseCode 将错误解析为错误码错误 若err不是错误码错误,则包裹传递错误,其他信息为默认错误码信息 若err为错误码错误,将其转换,将最外层错误信息作为最终错误信息返回 若想得到原始的错误码错误,可以使用As方法
func SetAppCode ¶ added in v0.3.0
func SetAppCode[T codeType](code T)
SetAppCode 设置服务错误码 模块码、模块错误码一共四位,指定应用码将拼接在前 例如应用码位101,模块码为1,模块错误码为21,那么最终业务错误码为:1010121
func SetDefault ¶ added in v0.3.0
SetDefault 设置默认错误码 当错误码匹配失败时,提供的备选方案,已内置默认错误码, 它的HTTP码为200,业务码和信息均为零值
func TransferFromError ¶
TransferFromError 将错误转为带栈帧的错误 Deprecated: 请使用 New、 Wrap、 WithCode、 WithStack
func UnWrap ¶ added in v0.3.0
UnWrap 获取包装过的error 若error1使用 Wrap 包装后产出错误error2 当使用 UmWrap 后,返回的是error1
Types ¶
type ErrCode ¶ added in v0.3.0
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 ¶ added in v0.3.0
func NewBadRequest ¶ added in v0.3.0
func NewConflict ¶ added in v0.3.0
func NewForbidden ¶ added in v0.3.0
func NewGenerateNameConflict ¶ added in v0.3.0
func NewInternalError ¶ added in v0.3.0
func NewMethodNotSupported ¶ added in v0.3.0
func NewNotFound ¶ added in v0.3.0
func NewRequestEntityTooLargeError ¶ added in v0.3.0
func NewServiceUnavailable ¶ added in v0.3.0
func NewTimeoutError ¶ added in v0.3.0
func NewTooManyRequests ¶ added in v0.3.0
func NewTooManyRequestsError ¶ added in v0.3.0
func NewUnauthorized ¶ added in v0.3.0
Click to show internal directories.
Click to hide internal directories.