errc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Index

Constants

View Source
const (
	Failed  = -1
	Success = 0

	InternalErr = 1

	AuthInternalErr      = 10
	AuthRequired         = 11
	AuthExpired          = 12
	AuthInvalid          = 13
	AuthSignatureInvalid = 14

	ParamRequired = 20
	ParamInvalid  = 21

	NotFound = 404
)

-1--999 system common error code

Variables

View Source
var Lang = "EN"
View Source
var Messages = map[int]string{
	Failed:               "Failed",
	Success:              "Ok",
	InternalErr:          "Internal error",
	AuthInternalErr:      "Auth internal error",
	AuthRequired:         "Auth Authorization header required",
	AuthExpired:          "Auth expired",
	AuthInvalid:          "Auth invalid",
	AuthSignatureInvalid: "Auth signature invalid",

	ParamRequired: "Param required",
	ParamInvalid:  "Param validator invalid",

	NotFound: "Not found",
}
View Source
var MessagesCN = map[int]string{
	Failed:      "失败",
	Success:     "成功",
	InternalErr: "内部错误",

	AuthInternalErr:      "权限内部错误",
	AuthRequired:         "权限请求头必传",
	AuthExpired:          "权限过期",
	AuthInvalid:          "权限无效",
	AuthSignatureInvalid: "权限签名无效",

	ParamRequired: "参数必传",
	ParamInvalid:  "参数验证无效",
	NotFound:      "资源不存在",
}

Functions

func GetMessage

func GetMessage(code int) string

func MultiError

func MultiError(err ...error) error

func SetLang

func SetLang(lang string)

func ToInternalError

func ToInternalError(err error) error

ToInternalError if not Error, to internal error

func WithStack

func WithStack(err error) error

Types

type Error

type Error struct {
	Code    int      `json:"code" xml:"code"`
	Message string   `json:"message" xml:"message"`
	Stack   []string `json:"-" xml:"-"`
}

func Message

func Message(msg string) Error

func NewError

func NewError(code int, msg string) Error

func (Error) CodeMsg

func (e Error) CodeMsg() (int, string)

func (Error) Error

func (e Error) Error() string

func (Error) MultiErr

func (e Error) MultiErr(err error) Error

func (Error) MultiMsg

func (e Error) MultiMsg(v ...interface{}) Error

Jump to

Keyboard shortcuts

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