package errcode import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) // SuccessMsg 自定义成功消息 var SuccessMsg = "成功" var SuccessCode = 200 func SetSuccessMsg(msg string) { SuccessMsg = msg } type BusinessErr struct { Code int32 Message string } func (e *BusinessErr) Error() string { return e.Message } func (e *BusinessErr) GRPCStatus() *status.Status { var code = codes.Code(e.Code) return status.New(code, e.Message) } // CustomErr 自定义错误 func CustomErr(code int32, message string) *BusinessErr { return &BusinessErr{Code: code, Message: message} } var ( NotFoundErr = &BusinessErr{Code: 404, Message: "资源未找到"} ParamError = &BusinessErr{Code: 400, Message: "参数错误"} //未经授权 NotAuth = &BusinessErr{Code: 401, Message: "未授权"} EnCrypt = &BusinessErr{Code: 401, Message: "加密失败"} DeCrypt = &BusinessErr{Code: 401, Message: "解密失败"} //请求被禁止 Forbidden = &BusinessErr{Code: 403, Message: "禁止访问"} WhiteIp = &BusinessErr{Code: 403, Message: "访问IP,不在白名单内"} //系统错误 SystemError = &BusinessErr{Code: 500, Message: "系统错误"} ThirtyDayQueryLimit = &BusinessErr{Code: 420, Message: "只能查询最近31天的数据"} GoodsSameErr = &BusinessErr{Code: 404, Message: "存在相同货品编码|货品名称的商品,请检查后重试"} HadDefaultWareHouseErr = &BusinessErr{Code: 400, Message: "该商品已存在默认仓,请检查后重试"} HadSameSupplierRelation = &BusinessErr{Code: 400, Message: "已存在相同的供应商商品关系,请检查后重试"} AppRsaEncryptKeyNotFound = &BusinessErr{Code: 400, Message: "密钥缺失"} AppRsaEncryptFail = &BusinessErr{Code: 400, Message: "Rsa加密失败"} AppRsaDecryptKeyNotFound = &BusinessErr{Code: 400, Message: "密钥缺失"} AppRsaDecryptFail = &BusinessErr{Code: 400, Message: "Rsa解密失败"} AppSM2EncryptKeyNotFound = &BusinessErr{Code: 400, Message: "密钥缺失"} AppSM2EncryptFail = &BusinessErr{Code: 400, Message: "Sm2加密失败"} AppSM2DecryptKeyNotFound = &BusinessErr{Code: 400, Message: "密钥缺失"} AppSM2DecryptFail = &BusinessErr{Code: 400, Message: "Sm2解密失败"} AppSM4EncryptKeyNotFound = &BusinessErr{Code: 400, Message: "密钥缺失"} AppSM4EncryptFail = &BusinessErr{Code: 400, Message: "Sm4加密失败"} AppSM4DecryptKeyNotFound = &BusinessErr{Code: 400, Message: "密钥缺失"} AppSM4DecryptFail = &BusinessErr{Code: 400, Message: "Sm4解密失败"} BalanceNotEnough = &BusinessErr{Code: 400, Message: "余额不足"} CusStatusException = &BusinessErr{Code: 400, Message: "客户状态异常"} HadSameCusGoods = &BusinessErr{Code: 400, Message: "已存在相同的客户商品授权,请检查后重试"} )