ecode

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BadRequestCode  = 400
	ServerErrorCode = 500
)

Variables

This section is empty.

Functions

func Errorf

func Errorf(code int, format string, args ...interface{}) error

func SetSysErrorCode

func SetSysErrorCode(whitelist, blacklist arr2d)

SetSysErrorCode 设置系统错误的错误码,二维数组中每个元素代表一个区间

使用whitelist-blacklist即差集来判断是否系统错误, 示例

sys_err:

whitelist: # 白名单,在列表的错误码表示系统错误,为空表示所有大于0的错误码
- [1, 1000] # 区间[1, 1000]
- [5000] # 错误码为5000
blacklist: # 黑名单,在列表的错误码表示不是系统错误
- [0, 1000]

func ToErrorCode

func ToErrorCode(err error) (string, string, bool)

ToErrorCode 将error转成错误码,并返回是否是系统错误

func ToHttpCode

func ToHttpCode(err error) int

ToHttpCode 将error转成http错误码(200/400/500)

Types

type APIError

type APIError struct {
	// Error Code
	Code int `json:"code"`
	// Error Message
	Message string `json:"message"`
	// Trace ID
	TraceId string `json:"traceID,omitempty"`
}

APIError describe the error message

func (*APIError) Error

func (e *APIError) Error() string

Jump to

Keyboard shortcuts

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