Documentation ¶
Index ¶
- Variables
- func EqualError(code Coder, err error) bool
- func FormatMicroError(err error) error
- func MicroCallFunc(fn client.CallFunc) client.CallFunc
- func MicroHandlerFunc(fn server.HandlerFunc) server.HandlerFunc
- func NewError(message string) error
- func ParseMicroError(err error) error
- func RetryOnMicroError(ctx context.Context, req client.Request, retryCount int, err error) (bool, error)
- func Unwrap(e error) error
- func Wrap(e error, message string) error
- func Wrapf(e error, format string, args ...interface{}) error
- type Code
- type Coder
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 成功 Success = add(200, "success") // 无效的请求 ErrBadRequest = add(400, "bad request") ErrUnauthorized = add(401, "unauthorized") // 拒绝执行 //ErrForbidden = add(403, "forbidden") // 资源找不到 ErrNotFound = add(404, "not found") // 请求方法不支持 ErrMethodNotAllowed = add(405, "method not allowed") // 服务请求超时 ErrRequestTimeout = add(408, "request timeout") // 请求过于频繁 ErrTooManyRequests = add(429, "too many requests") // 服务内部错误 ErrInternalServer = add(500, "internal server") )
Functions ¶
func EqualError ¶
func FormatMicroError ¶
func MicroHandlerFunc ¶
func MicroHandlerFunc(fn server.HandlerFunc) server.HandlerFunc
服务端 - 格式化成 ecode 错误
func ParseMicroError ¶
Types ¶
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
func New ¶
New new a ecode.Codes by int value. NOTE: ecode must unique in global, the New will check repeat and then panic.
func (Code) ResetMessage ¶
ResetMessage reset error message
type Coder ¶
type Coder interface { // sometimes Error return Code in string form // NOTE: don't use Error in monitor report even it also work for now Error() string // Code get error code. Code() int // Message get code message. Message() string // Message reset code message. ResetMessage(message string) error //Detail get error detail,it may be nil. Details() []interface{} // Equal for compatible. // Deprecated: please use ecode.EqualError. Equal(error) bool }
Codes ecode error interface which has a code & message.
Click to show internal directories.
Click to hide internal directories.