errno

package
v0.0.0-...-234e9da Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 访问成功
	OK = &Errno{Code: 1, Message: "OK"}
	// -- 内部服务错误
	ErrSystem            = &Errno{Code: 10000, Message: "服务器内部错误"}
	ErrGetServerIpAddr   = &Errno{Code: 10001, Message: "获取服务器IP地址异常"}
	ErrServiceNotRunning = &Errno{Code: 10002, Message: "服务并未启动"}
	ErrExecConfigFailed  = &Errno{Code: 10003, Message: "执行配置失败"}
	ErrFileReadFailed    = &Errno{Code: 10004, Message: "文件读取失败"}
	ErrExecIllegal       = &Errno{Code: 10005, Message: "非法操作"}
	ErrLoggerIsNil       = &Errno{Code: 10006, Message: "日志对象为空"}
	ErrLoginFail         = &Errno{Code: 10007, Message: "登录失败"}

	// -- -- 数据类型转换异常
	ErrTypeConversion     = &Errno{Code: 11001, Message: "数据类型转换异常"}
	ErrByteArr2JSON       = &Errno{Code: 11002, Message: "字节数组转json异常"}
	ErrJSON2ByteArr       = &Errno{Code: 11003, Message: "json转字节数组异常"}
	ErrMD5EncryptFailed   = &Errno{Code: 11004, Message: "MD5加密异常"}
	ErrObjectIsNil        = &Errno{Code: 11005, Message: "实体不能为空"}
	ErrBase64toFileFailed = &Errno{Code: 11006, Message: "Base64字符串转文件异常"}

	// -- --请求参数异常
	ErrRequestParamsNil                       = &Errno{Code: 12001, Message: "请求参数为不能为空"}
	ErrVerifyCodeFailed                       = &Errno{Code: 12002, Message: "提交的验证码有误"}
	ErrVerifyPhoneFormatFailed                = &Errno{Code: 12003, Message: "提交的手机号码格式有误"}
	ErrQueryTimeStampParamsCount              = &Errno{Code: 12004, Message: "时间戳查询参数个数不能大于2"}
	ErrStartTimeStampMustLessThanEndTimeStamp = &Errno{Code: 12005, Message: "开始时间戳必须小于结束时间戳"}

	// -- 业务模块异常 (2xxxx)
	ErrGetAppVersionInfoFailed = &Errno{Code: 20001, Message: "获取应用版本信息异常"}

	// -- -- 用户相关异常
	ErrPlatfromUserUserNameExist   = &Errno{Code: 21001, Message: "用户名已在平台注册"}
	ErrPlatfromUserPhoneExist      = &Errno{Code: 21002, Message: "手机号已在平台注册"}
	ErrPlatfromUserPhoneNotExist   = &Errno{Code: 21003, Message: "手机号码不存在"}
	ErrValidateSmsVerifyCodeFailed = &Errno{Code: 21004, Message: "短信验证码校验失败"}
	ErrVerifyPasswordFailed        = &Errno{Code: 21005, Message: "密码校验失败"}
	ErrVerifyTwoPasswordFailed     = &Errno{Code: 21006, Message: "两段密码不一致"}
	ErrVerifyOldPasswordFailed     = &Errno{Code: 21007, Message: "原密码校验失败"}
	ErrGetParamsFromTokenNil       = &Errno{Code: 21008, Message: "从token获取参数异常"}
	ErrRequestFailedByUserType     = &Errno{Code: 21009, Message: "用户类型不匹配,不能访问当前接口"}
	ErrScoreDeductNotEnough        = &Errno{Code: 21010, Message: "操作异常:当前积分小于扣除积分"}
	ErrUserInfoNotDefined          = &Errno{Code: 21011, Message: "用户信息未定义"}
	ErrAccessPathForbidden         = &Errno{Code: 21012, Message: "权限不足无法访问"}
	ErrUserNotAllowUse             = &Errno{Code: 21013, Message: "当前账户不允许登录"}

	// -- -- 订单相关异常
	ErrGoodsTypeNotDefined               = &Errno{Code: 22001, Message: "商品类型未定义"}
	ErrPayTypeError                      = &Errno{Code: 22002, Message: "支付方式错误"}
	ErrPayTypeNotDefined                 = &Errno{Code: 22003, Message: "支付方式未定义"}
	ErrPayTypeNotWork                    = &Errno{Code: 22004, Message: "提交的支付方式暂未实现"}
	ErrDeviceEffectiveInventoryNotEnough = &Errno{Code: 22005, Message: "有效设备数量不足"}
	ErrOrderCalculateSumAmountFail       = &Errno{Code: 22006, Message: "订单总金额异常"}
	ErrOrderUserTypeNotDefined           = &Errno{Code: 22007, Message: "订单用户类型未定义"}
	ErrGoodsNotEnough                    = &Errno{Code: 22008, Message: "商品数量不足"}
	ErrUserScorePayForGoodsNotEnough     = &Errno{Code: 22009, Message: "用户当前积分不足以支付商品所需积分"}
	ErrOrderQueryInsufficientAuthority   = &Errno{Code: 22010, Message: "订单查询权限不足"}
	ErrRenewalFeeListEmpty               = &Errno{Code: 22011, Message: "续费列表不能为空"}
	ErrDeviceNotBelongToCurrentUser      = &Errno{Code: 22012, Message: "设备存在不属于当前用户异常"}
	ErrOrderStatusNoDefined              = &Errno{Code: 22013, Message: "不存在相关的订单状态"}
	ErrGoodsNoDefined                    = &Errno{Code: 22014, Message: "不存在相关的订单状态"}
	ErrDeviceTypeNotMatch                = &Errno{Code: 22015, Message: "提交设备列表种类不一致"}
	ErrIdcNotFound                       = &Errno{Code: 22016, Message: "查找不到相关的IDC机房"}

	// -- -- 支付相关异常
	ErrPayCommon                              = &Errno{Code: 23001, Message: "支付异常"}
	ErrWechatUnifiedOrderRequestFailed        = &Errno{Code: 23002, Message: "微信支付统一下单请求失败"}
	ErrWechatUnifiedOrderResponseVerifyFailed = &Errno{Code: 23003, Message: "微信支付统一下单响应校验失败"}
	ErrWechatGetNotifyRequestFailed           = &Errno{Code: 23004, Message: "微信支付获取回调结果失败"}
	ErrWechatVerifyNotifyInfoFailed           = &Errno{Code: 23005, Message: "微信支付校验回调信息失败"}
	ErrAliGeneratePayInitFailed               = &Errno{Code: 23006, Message: "支付宝初始化赋值client失败"}
	ErrAliGeneratePayUrlFailed                = &Errno{Code: 23007, Message: "支付宝生成支付网址失败"}

	// -- -- 商品券异常
	ErrGoodsTicketHasBeenActived    = &Errno{Code: 24001, Message: "商品券已经使用"}
	ErrGoodsTicketHasNotBeenActived = &Errno{Code: 24002, Message: "商品券还没使用"}
	ErrGoodsTicketNotAlive          = &Errno{Code: 24003, Message: "商品券不存在"}
	ErrGoodsTicketUseStatusNotAlive = &Errno{Code: 24004, Message: "商品券使用状态不存在"}
	ErrGoodsFinishDelivery          = &Errno{Code: 24005, Message: "商品券已经发过货了,请勿重复提交"}

	// -- -- 设备异常
	ErrNoChipTypeDevice = &Errno{Code: 25001, Message: "没有当前芯片的设备"}

	// -- 中间件异常(3xxxx)
	// -- -- Redis异常
	ErrRedisConnNotFound        = &Errno{Code: 31001, Message: "获取Redis Conn失败"}
	ErrRedisInsertFailed        = &Errno{Code: 31002, Message: "Redis插入数据失败"}
	ErrRedisDeleteFailed        = &Errno{Code: 31003, Message: "Redis删除数据失败"}
	ErrRedisGetDataFailed       = &Errno{Code: 31004, Message: "Redis获取数据失败"}
	ErrRedisCreateServiceFailed = &Errno{Code: 31005, Message: "Redis创建服务失败"}

	// -- MySQL数据库相关
	ErrSetAutoCommitCloseFailed = &Errno{Code: 32001, Message: "设置关闭会话级别的自动提交失败"}
	ErrGetTaskLockFailed        = &Errno{Code: 32002, Message: "获取事务的悲观锁失败"}
	ErrMySQLQuery               = &Errno{Code: 32003, Message: "数据库查询异常"}
	ErrMySQLEmptyRecord         = &Errno{Code: 32004, Message: "查询记录为空"}
	ErrMySQLUpdateFailed        = &Errno{Code: 32005, Message: "数据库更新失败"}
	ErrMySQLCreateTxFailed      = &Errno{Code: 32006, Message: "创建事务失败"}
	ErrMySQLCommitTxFailed      = &Errno{Code: 32007, Message: "提交事务失败"}
	ErrMySQLInsertFailed        = &Errno{Code: 32008, Message: "数据库创建记录异常"}
	ErrMySQLSumCountFailed      = &Errno{Code: 32009, Message: "数据库分页查询总数异常"}
	ErrMySQLScanFailed          = &Errno{Code: 32010, Message: "数据库原生查询Scan异常"}
	ErrMySQLPrimaryKeyNotNil    = &Errno{Code: 32011, Message: "数据库查询,主键不能为空"}

	// -- -- RabbitMQ异常
	ErrRabbitMQInitConnectionFailed    = &Errno{Code: 33001, Message: "RabbitMQ Connection构造失败"}
	ErrRabbitMQCloseConnectionFailed   = &Errno{Code: 33002, Message: "RabbitMQ 关闭Connection失败"}
	ErrRabbitMQCloseChannelFailed      = &Errno{Code: 33003, Message: "RabbitMQ 关闭Channel失败"}
	ErrRabbitMQInitChannelFailed       = &Errno{Code: 33004, Message: "RabbitMQ Channel构造失败"}
	ErrRabbitMQInitQueueFailed         = &Errno{Code: 33005, Message: "RabbitMQ Queue构造失败"}
	ErrRabbitMQInitExchangeFailed      = &Errno{Code: 33006, Message: "RabbitMQ Exchange构造失败"}
	ErrRabbitMQBindTopicFailed         = &Errno{Code: 33007, Message: "RabbitMQ 绑定Topic失败"}
	ErrRabbitMQConsumeFailed           = &Errno{Code: 33008, Message: "RabbitMQ 执行Consume方法失败"}
	ErrRabbitMQPublishMessageFailed    = &Errno{Code: 33009, Message: "RabbitMQ 发送消息方法失败"}
	ErrRabbitMQConsumeAckConfirmFailed = &Errno{Code: 33010, Message: "RabbitMQ 消费确认失败"}
	ErrRabbitChannelIsClosed           = &Errno{Code: 33011, Message: "RabbitMQ 消费channel已经关闭"}

	// -- -- RPC异常
	ErrInitRpcClient    = &Errno{Code: 34001, Message: "初始化RPC Client失败"}
	ErrOpenRpcClient    = &Errno{Code: 34002, Message: "开启RPC Client失败"}
	ErrCloseRpcClient   = &Errno{Code: 34003, Message: "关闭RPC Client失败"}
	ErrRpcClientRequest = &Errno{Code: 34004, Message: "RPC Client访问失败"}

	// -- -- 鉴权部分
	// -- -- JWT校验
	ErrJwtMissing = &Errno{Code: 35101, Message: "token参数缺失"}
	// -- -- OAUTH2校验
	ErrOAuth2ObtainFailed      = &Errno{Code: 35201, Message: "OAuth2 Token获取失败"}
	ErrOAuth2VerifyTokenFailed = &Errno{Code: 35202, Message: "OAuth2 Token校验失败"}
	ErrOAuth2CredentialsFailed = &Errno{Code: 35203, Message: "OAuth2 获取clientID,ClientSerect失败"}

	// -- -- consul 异常
	ErrConsulDiscoveryServiceFailed = &Errno{Code: 36001, Message: "Consul 服务发现异常"}

	// -- -- aliyun 阿里云
	ErrAliyunOssInitClientFailed = &Errno{Code: 37001, Message: "阿里云OSS初始化客户端异常"}
	ErrAliyunOssInitBucketFailed = &Errno{Code: 37002, Message: "阿里云OSS初始化Bucket异常"}
	ErrAliyunOssUploadFileFailed = &Errno{Code: 37002, Message: "阿里云OSS上传文件失败"}

	// -- -- 4xxxx 用户需要处理的异常
	ErrBind                 = &Errno{Code: 40001, Message: "上传参数绑定异常"}                          // iris绑定json异常
	ErrValidation           = &Errno{Code: 40002, Message: "验证失败"}                              // 如果出现表单校验异常,是需要客户端自行处理与显示的
	ErrUsernamePasswordFail = &Errno{Code: 40003, Message: "账号与密码不匹配"}                          // 如果出现表单校验异常,是需要客户端自行处理与显示的
	ErrPlatformUserNotFound = &Errno{Code: 40004, Message: "无法找到指定的平台用户"}                       // 如果出现表单校验异常,是需要客户端自行处理与显示的
	ErrRegexpUserName       = &Errno{Code: 40005, Message: "用户名不符合规则,至少6位,不能包含特殊字符(下划线/中划线除外)"} // 如果出现表单校验异常,是需要客户端自行处理与显示的
	ErrRegexpNickName       = &Errno{Code: 40006, Message: "昵称不符合规则,至少2位"}                      // 如果出现表单校验异常,是需要客户端自行处理与显示的
	ErrRegexpPassword       = &Errno{Code: 40007, Message: "密码不符合规则,至少6位,不能包含中文"}               // 如果出现表单校验异常,是需要客户端自行处理与显示的
)

1xxxx 开头为系统级别的常规异常 2xxxx 开头为业务几倍的常规异常 3xxxx 开头为中间件或者其他通用服务的常规异常 4xxxx 开头为接口使用者需要处理的异常[其实一般的接口,只需要返回什么错误内容,显示即可,但部分接口是需要客户端自己处理的,例如表单的提交异常]

Functions

func DecodeErr

func DecodeErr(err error) (int, string)

Types

type Err

type Err struct {
	Code    int
	Message string
	Err     error
}

Err represents an error

func New

func New(errno *Errno, err error) *Err

func (*Err) Add

func (err *Err) Add(message string) error

func (*Err) Addf

func (err *Err) Addf(format string, args ...interface{}) error

func (*Err) Error

func (err *Err) Error() string

type Errno

type Errno struct {
	Code    int
	Message string
}

错误代码的集中处理

func (Errno) Error

func (err Errno) Error() string

Jump to

Keyboard shortcuts

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