ecode

package
v0.0.0-...-8587cce Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK = add(0) // 正确

	AppKeyInvalid           = add(-1)    // 应用程序不存在或已被封禁
	AccessKeyErr            = add(-2)    // Access Key错误
	SignCheckErr            = add(-3)    // API校验密匙错误
	MethodNoPermission      = add(-4)    // 调用方对该Method没有权限
	NoLogin                 = add(-101)  // 账号未登录
	UserDisabled            = add(-102)  // 账号被封停
	LackOfScores            = add(-103)  // 积分不足
	LackOfCoins             = add(-104)  // 硬币不足
	CaptchaErr              = add(-105)  // 验证码错误
	UserInactive            = add(-106)  // 账号未激活
	UserNoMember            = add(-107)  // 账号非正式会员或在适应期
	AppDenied               = add(-108)  // 应用不存在或者被封禁
	MobileNoVerify          = add(-110)  // 未绑定手机
	CsrfNotMatchErr         = add(-111)  // csrf 校验失败
	ServiceUpdate           = add(-112)  // 系统升级中
	UserIDCheckInvalid      = add(-113)  // 账号尚未实名认证
	UserIDCheckInvalidPhone = add(-114)  // 请先绑定手机
	UserIDCheckInvalidCard  = add(-115)  // 请先完成实名认证
	NotModified             = add(-304)  // 木有改动
	RequestErr              = add(-400)  // 请求错误
	Unauthorized            = add(-401)  // 未认证
	AccessDenied            = add(-403)  // 访问权限不足
	NothingFound            = add(-404)  // 啥都木有
	MethodNotAllowed        = add(-405)  // 不支持该方法
	Conflict                = add(-409)  // 冲突
	ServerErr               = add(-500)  // 服务器错误
	ServiceUnavailable      = add(-503)  // 过载保护,服务暂不可用
	Deadline                = add(-504)  // 服务调用超时
	LimitExceed             = add(-509)  // 超出限制
	FileNotExists           = add(-616)  // 上传文件不存在
	FileTooLarge            = add(-617)  // 上传文件太大
	FailedTooManyTimes      = add(-625)  // 登录失败次数太多
	UserNotExist            = add(-626)  // 用户不存在
	PasswordTooLeak         = add(-628)  // 密码太弱
	UsernameOrPasswordErr   = add(-629)  // 用户名或密码错误
	TargetNumberLimit       = add(-632)  // 操作对象数量限制
	TargetBlocked           = add(-643)  // 被锁定
	UserLevelLow            = add(-650)  // 用户等级太低
	UserDuplicate           = add(-652)  // 重复的用户
	AccessTokenExpires      = add(-658)  // Token 过期
	PasswordHashExpires     = add(-662)  // 密码时间戳过期
	Degrade                 = add(-1200) // 被降级过滤的请求
	RPCNoClient             = add(-1201) // rpc服务的client都不可用
	RPCNoAuth               = add(-1202) // rpc服务的client没有授权
)

All common ecode

Functions

func Equal

func Equal(a, b Codes) bool

Equal equal a and b by code int.

func EqualError

func EqualError(code Codes, err error) bool

EqualError equal error

func Register

func Register(cm map[int]string)

Register register ecode message map.

Types

type Code

type Code int

A Code is an int error code spec.

func Int

func Int(i int) Code

Int parse code int to error.

func New

func New(e int) Code

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

func String

func String(e string) Code

String parse code string to error.

func (Code) Code

func (e Code) Code() int

Code return error code

func (Code) Details

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

Details return details.

func (Code) Equal

func (e Code) Equal(err error) bool

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

func (Code) Error

func (e Code) Error() string

func (Code) Message

func (e Code) Message() string

Message return error message

type Codes

type Codes 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
	//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) Codes

Cause cause from error to ecode.

Jump to

Keyboard shortcuts

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