Documentation
¶
Index ¶
- Variables
- func Code(err error) int
- func HTTPCode(err error) int
- func Name(err error) string
- type Definition
- func (d *Definition) Error() string
- func (d *Definition) New(msg string) error
- func (d *Definition) Newf(format string, args ...interface{}) error
- func (d *Definition) WithHTTP(code int) *Definition
- func (d *Definition) Wrap(cause error, msg string) error
- func (d *Definition) Wrapf(cause error, format string, args ...interface{}) error
- type ErrorInfo
- type Registry
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Sentinel 错误定义,code 范围 2000-2999。 NotFound = Register(2001, "NOT_FOUND").WithHTTP(http.StatusNotFound) InvalidParam = Register(2002, "INVALID_PARAM").WithHTTP(http.StatusBadRequest) Forbidden = Register(2004, "FORBIDDEN").WithHTTP(http.StatusForbidden) Internal = Register(2005, "INTERNAL_ERROR").WithHTTP(http.StatusInternalServerError) Timeout = Register(2006, "TIMEOUT").WithHTTP(http.StatusGatewayTimeout) BadGateway = Register(2007, "BAD_GATEWAY").WithHTTP(http.StatusBadGateway) )
Functions ¶
Types ¶
type Definition ¶ added in v1.1.0
type Definition struct {
Code int
Name string
Class *Definition
HTTP int
}
Definition 描述一个错误定义。
func NewDefinition ¶ added in v1.1.0
func NewDefinition(name string) *Definition
NewDefinition 在全局注册表中创建或返回同名错误定义。
func Register ¶ added in v1.1.0
func Register(code int, name string) *Definition
Register 在全局注册表中注册错误定义。
func (*Definition) Error ¶ added in v1.1.0
func (d *Definition) Error() string
Error 让 Definition 可作为 errors.Is 的 target 使用。
func (*Definition) New ¶ added in v1.1.0
func (d *Definition) New(msg string) error
New 创建一个带当前定义的错误实例。
func (*Definition) Newf ¶ added in v1.1.0
func (d *Definition) Newf(format string, args ...interface{}) error
Newf 按格式化字符串创建错误实例。
func (*Definition) WithHTTP ¶ added in v1.1.0
func (d *Definition) WithHTTP(code int) *Definition
WithHTTP 返回附带 HTTP 状态码的新定义副本。
Click to show internal directories.
Click to hide internal directories.