123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- package exception
- import stringUtils "eta/eta_mini_ht_api/common/utils/string"
- type EtaError struct {
- ErrorCode int
- ErrorMsg string
- Exception string
- }
- func (e *EtaError) Error() string {
- return e.ErrorMsg
- }
- const (
- // SysErrCode 系统错误
- SysErrCode int = iota + 10000 // iota 自动递增,从 1 开始
- UnknownError
- Unauthorized
- SysError
- QueryRiskMappingError
- IllegalConfigType
- GetConfigValueFailed
- )
- // BIZErrCode 业务错误
- const (
- BIZErrCode int = iota + 20000 // iota 自动递增,从 1 开始
- //短信
- IllegalCodeLength
- IllegalPhoneNumber
- SMSCodeGenerateFailed
- SendingSMSFailed
- SMSCodeAlreadySent
- SMSCodeExpired
- SMSCodeError
- GetAreaCodesFailed
- AnalystNotFound
- IllegalAreaCode
- MediaTypeError
- GetAnalystListFailed
- BatchFollowingAnalystFailed
- )
- // UserErrCode 用户
- const (
- UserErrCode int = iota + 30000 // iota 自动递增,从 1 开始
- TemplateUserNotFound
- TemplateUserFoundFailed
- IllegalTemplateUserId
- TemplateUserCreateFailed
- TemplateUserBindFailed
- GenerateTokenFailed
- JWTTokenDecodeFailed
- LoginFailed
- LogoutFailed
- JWTTokenExpired
- JWTTokenInvalid
- NotCurrentUserError
- FeedBackMsgEmpty
- FeedBackError
- IllegalFollowType
- UserFollowAnalystFailed
- GetNoticeFileError
- GetDisclaimerFileError
- AnalystNameEmptyError
- IllegalAnalystIdError
- GetFollowingAnalystListFailed
- TransferFollowingAnalystListFailed
- GetUserUnReadMsgFailed
- IllegalMessageId
- IllegalAnalystId
- ReadMessageFailed
- BindMobileFailed
- CheckFollowStatusByNamesFailed
- RiskUnTestError
- RiskExpiredError
- RiskUnMatchError
- OfficialUserFoundError
- OfficialUserNotFound
- IllegalAccountStatus
- AccountNotOpen
- IDExpired
- SubscribeFailed
- DuplicateSubscribe
- GenerateOrderNoFailed
- IllegalOrderNo
- GetOrderListFailed
- GetOrderDetailFailed
- CloseOrderFailed
- GetBookMarkListFailed
- )
- // WechatErrCode 微信
- const (
- WechatErrCode int = iota + 40000 // iota 自动递增,从 1 开始
- WeChatServerError
- WeChatResponseError
- WechatUserInfoFailed
- WeChatCodeEmpty
- WeChatIllegalRequest
- WeChatConfigError
- WeChatQRCodeFailed
- )
- const (
- ReportErrCode int = iota + 50000 // iota 自动递增,从 1 开始
- GetPublishedRandListFailed
- GetPermissionListFailed
- ReportRecordClickCountFailed
- MediaRecordClickCountFailed
- GetHotRandListFailed
- QueryReportPageFailed
- SearchReportPageFailed
- GetReportFailed
- GetReportSearchRangeFailed
- SearchKeyEmptyError
- ReportRiskLevelUnSet
- ReportDeleted
- )
- const (
- MediaErrCode int = iota + 60000 // iota 自动递增,从 1 开始
- MediaFoundFailed
- GetMediaListFailed
- GetAnalystMediaListFailed
- ChartImageEmptyError
- IllegalChartId
- UpdateChartImageFailed
- )
- const (
- MerchantErrCode int = iota + 70000
- ProductInfoError
- IllegalProductId
- IllegalProductOrderId
- MerchantInfoNotConfig
- GetProductListFailed
- IllegalProductType
- )
- const (
- WebhookErrCode int = iota + 80000
- SyncRiskError
- GetCapTokenFailed
- GetCustomerRiskInfoFailed
- GenerateRiskTestTokenFailed
- )
- const (
- OrderErrorCode int = iota + 90000
- IllegalOrderStatus
- OrderPayTimeoutError
- PayTradeOrderFailed
- )
- const (
- ProductErrorCode int = iota + 100000
- ProductOffSale
- ProductNotFound
- ProductTypeError
- ProductGetFailed
- )
- const (
- PaymentErrCode int = iota + 110000
- CreatePaymentOrderFailed
- PaymentProcessingError
- PaymentDoneError
- RefundDealFail
- )
- const (
- BookMarkErrCode int = iota + 120000 // iota 自动递增,从 1 开始
- IllegalSourceType
- IllegalSearchKeyword
- IllegalSourceId
- BookMarkFailed
- BookMarkListFailed
- )
- // ErrorMap 用于存储错误码和错误信息的映射
- var ErrorMap = map[int]string{
- SysError: "系统异常",
- UnknownError: "未知错误",
- Unauthorized: "用户未授权",
- QueryRiskMappingError: "查询风险等级映射设置错误",
- IllegalCodeLength: "无效的验证码位数设置",
- IllegalPhoneNumber: "无效的手机号码",
- SMSCodeGenerateFailed: "生成手机验证码失败",
- SendingSMSFailed: "发送手机验证码失败",
- SMSCodeAlreadySent: "当前手机验证码已发送,请稍后再试",
- SMSCodeExpired: "验证码已过期",
- SMSCodeError: "验证码错误",
- AnalystNotFound: "研究员不存在",
- GetAreaCodesFailed: "获取手机区号失败",
- IllegalAreaCode: "无效的区号",
- MediaTypeError: "媒体类型非法",
- GetAnalystListFailed: "获取研究员列表失败",
- IllegalConfigType: "不合法的配置项值类型",
- GetConfigValueFailed: "配置获取失败",
- //用户
- TemplateUserNotFound: "临时用户记录不存在",
- LogoutFailed: "退出登录失败",
- LoginFailed: "登录失败",
- TemplateUserFoundFailed: "查询临时用户表失败",
- IllegalTemplateUserId: "不合法的临时用户ID",
- TemplateUserCreateFailed: "创建临时用户失败",
- TemplateUserBindFailed: "临时用户绑定小程序失败",
- GenerateTokenFailed: "创建token失败",
- JWTTokenDecodeFailed: "token解析失败",
- JWTTokenExpired: "token已过期",
- JWTTokenInvalid: "token无效",
- NotCurrentUserError: "用户信息不一致,非当前手机用户操作",
- FeedBackMsgEmpty: "反馈信息不能为空",
- FeedBackError: "提交反馈信息失败",
- IllegalFollowType: "无效的关注类型",
- UserFollowAnalystFailed: "关注研究员失败",
- GetNoticeFileError: "获取注册须知失败",
- GetDisclaimerFileError: "获取免责声明失败",
- AnalystNameEmptyError: "研究员姓名不能为空",
- GetFollowingAnalystListFailed: "获取关注研究员列表失败",
- TransferFollowingAnalystListFailed: "转换关注研究员列表失败",
- GetUserUnReadMsgFailed: "获取未读消息列表失败",
- IllegalMessageId: "非法的消息ID",
- ReadMessageFailed: "已读消息失败",
- IllegalAnalystId: "研究员Id非法",
- CheckFollowStatusByNamesFailed: "获取关注猪状态失败",
- BatchFollowingAnalystFailed: "批量关注研究员列表失败",
- RiskUnTestError: "客户未做风险测评",
- RiskExpiredError: "客户风险测评已过期",
- RiskUnMatchError: "客户风险测评不匹配",
- OfficialUserFoundError: "获取正式用户信息失败",
- OfficialUserNotFound: "用户未开户",
- IllegalAccountStatus: "非法的开户状态",
- SubscribeFailed: "订阅失败",
- DuplicateSubscribe: "重复订阅",
- GenerateOrderNoFailed: "生成订单号",
- IllegalOrderNo: "非法的商品订单号",
- GetOrderListFailed: "获取产品订单列表失败",
- GetOrderDetailFailed: "获取订单详情失败",
- CloseOrderFailed: "关闭订单失败",
- GetBookMarkListFailed: "获取收藏列表失败",
- //微信
- WeChatServerError: "微信服务器发生错误",
- WechatUserInfoFailed: "获取微信用户信息失败",
- WeChatResponseError: "解析微信响应数据失败",
- WeChatCodeEmpty: "微信获取用户信息,code不能为空",
- WeChatIllegalRequest: "不合法的微信请求",
- WeChatConfigError: "微信配置获取失败",
- WeChatQRCodeFailed: "二维码生成失败",
- //研报
- GetPublishedRandListFailed: "获取已发布研报列表失败",
- GetPermissionListFailed: "获取品种列表失败",
- ReportRecordClickCountFailed: "添加点击访问次数失败",
- MediaRecordClickCountFailed: "添加媒体点击访问次数失败",
- GetHotRandListFailed: "获取热门研报列表失败",
- QueryReportPageFailed: "分页查询报告列表失败",
- SearchReportPageFailed: "分页搜索报告列表失败",
- GetReportFailed: "获取研报详情失败",
- ReportDeleted: "研报已删除",
- GetReportSearchRangeFailed: "设置报告搜索范围失败",
- SearchKeyEmptyError: "搜索关键字不能为空",
- ReportRiskLevelUnSet: "报告未设置风险等级",
- //媒体
- MediaFoundFailed: "查询媒体信息失败",
- GetMediaListFailed: "查询媒体列表失败",
- GetAnalystMediaListFailed: "查询研究员媒体列表失败",
- BindMobileFailed: "绑定手机号失败",
- ChartImageEmptyError: "图表缩略图url不能为空",
- IllegalChartId: "非法的图表ID",
- UpdateChartImageFailed: "更新图表缩略图失败",
- //商户
- ProductInfoError: "获取商品信息失败",
- IllegalProductId: "非法的产品ID",
- IllegalProductOrderId: "非法的产品订单ID",
- MerchantInfoNotConfig: "商户信息未配置",
- GetProductListFailed: "获取产品列表失败",
- IllegalProductType: "非法的产品类型",
- //webhook
- SyncRiskError: "同步风险等级失败",
- GetCapTokenFailed: "获取cap token失败",
- GenerateRiskTestTokenFailed: "生成风险测评token失败",
- GetCustomerRiskInfoFailed: "查询客户风险信息失败",
- //order
- IllegalOrderStatus: "非法的订单状态",
- OrderPayTimeoutError: "订单支付超时",
- PayTradeOrderFailed: "订单支付失败",
- //product
- ProductOffSale: "商品已下架",
- ProductTypeError: "非法的产品类型",
- ProductGetFailed: "获取商品信息失败",
- ProductNotFound: "商品不存在",
- //支付
- CreatePaymentOrderFailed: "创建支付订单失败",
- PaymentProcessingError: "支付订单处理中",
- PaymentDoneError: "订单已完成支付",
- RefundDealFail: "处理退款应答失败",
- //收藏
- IllegalSourceType: "非法的资源类型",
- IllegalSourceId: "非法的资源ID",
- BookMarkFailed: "收藏失败",
- BookMarkListFailed: "获取收藏列表失败",
- IllegalSearchKeyword: "搜索关键字不能为空",
- }
- func Equals(code int, message string) bool {
- if stringUtils.IsEmptyOrNil(message) {
- return false
- }
- return ErrorMap[code] == message
- }
- func GetMsg(code int) string {
- return ErrorMap[code]
- }
- func newException(code int, msg string) error {
- return &EtaError{
- ErrorCode: code,
- ErrorMsg: msg,
- }
- }
- func newExceptionWithOrgMsg(code int, msg string, exception string) error {
- return &EtaError{
- ErrorCode: code,
- ErrorMsg: msg,
- Exception: exception,
- }
- }
- func New(code int) *EtaError {
- err := ErrorMap[code]
- if stringUtils.IsBlank(err) {
- return newException(UnknownError, ErrorMap[UnknownError]).(*EtaError)
- }
- return newException(code, err).(*EtaError)
- }
- func NewWithException(code int, exception string) *EtaError {
- err := ErrorMap[code]
- if stringUtils.IsBlank(err) {
- return newException(UnknownError, ErrorMap[UnknownError]).(*EtaError)
- }
- return newExceptionWithOrgMsg(code, err, exception).(*EtaError)
- }
|