ecode

package
v1.0.1-rel-02 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: AFL-3.0 Imports: 9 Imported by: 0

Documentation

Index

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 EqualError(code Coder, err error) bool

func FormatMicroError

func FormatMicroError(err error) error

func MicroCallFunc

func MicroCallFunc(fn client.CallFunc) client.CallFunc

客户端 - 解析成 ecode 错误

func MicroHandlerFunc

func MicroHandlerFunc(fn server.HandlerFunc) server.HandlerFunc

服务端 - 格式化成 ecode 错误

func NewError

func NewError(message string) error

func ParseMicroError

func ParseMicroError(err error) error

func RetryOnMicroError

func RetryOnMicroError(ctx context.Context, req client.Request, retryCount int, err error) (bool, error)

自定义请求错误重试

func Unwrap

func Unwrap(e error) error

func Wrap

func Wrap(e error, message string) error

func Wrapf

func Wrapf(e error, format string, args ...interface{}) error

Types

type Code

type Code struct {
	// contains filtered or unexported fields
}

func New

func New(e int, m string) Code

New new a ecode.Codes by int value. NOTE: ecode must unique in global, the New will check repeat and then panic.

func (Code) Code

func (c Code) Code() int

Code return error code

func (Code) Details

func (c Code) Details() []interface{}

Details return details.

func (Code) Equal

func (c Code) Equal(err error) bool

Equal for compatible. Deprecated: please use ecode.EqualError.

func (Code) Error

func (c Code) Error() string

func (Code) Message

func (c Code) Message() string

Message return error message

func (Code) ResetMessage

func (c Code) ResetMessage(message string) error

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.

func Cause

func Cause(e error) Coder

Cause cause from error to ecode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL