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 ) // 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 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 SubscribeFailed GenerateOrderNoFailed IllegalOrderNo GetOrderListFailed ) // WechatErrCode 微信 const ( WechatErrCode int = iota + 40000 // iota 自动递增,从 1 开始 WeChatServerError WeChatResponseError WechatUserInfoFailed WeChatCodeEmpty WeChatIllegalRequest ) const ( ReportErrCode int = iota + 50000 // iota 自动递增,从 1 开始 GetPublishedRandListFailed GetPermissionListFailed ReportRecordClickCountFailed MediaRecordClickCountFailed GetHotRandListFailed QueryReportPageFailed SearchReportPageFailed GetReportFailed GetReportSearchRangeFailed SearchKeyEmptyError ReportRiskLevelUnSet ) const ( MediaErrCode int = iota + 60000 // iota 自动递增,从 1 开始 MediaFoundFailed GetMediaListFailed GetAnalystMediaListFailed ) const ( MerchantErrCode int = iota + 70000 ProductInfoError IllegalProductId IllegalProductOrderId ) const ( WebhookErrCode int = iota + 80000 SyncRiskError GetCapTokenFailed GenerateRiskTestTokenFailed ) const ( OrderErrorCode int = iota + 90000 IllegalOrderStatus OrderPayTimeoutError ) // ErrorMap 用于存储错误码和错误信息的映射 var ErrorMap = map[int]string{ SysError: "系统异常", UnknownError: "未知错误", Unauthorized: "用户未授权", QueryRiskMappingError: "查询风险等级映射设置错误", IllegalCodeLength: "无效的验证码位数设置", IllegalPhoneNumber: "无效的手机号码", SMSCodeGenerateFailed: "生成手机验证码失败", SendingSMSFailed: "发送手机验证码失败", SMSCodeAlreadySent: "当前手机验证码已发送,请稍后再试", SMSCodeExpired: "验证码已过期", SMSCodeError: "验证码错误", AnalystNotFound: "研究员不存在", GetAreaCodesFailed: "获取手机区号失败", IllegalAreaCode: "无效的区号", MediaTypeError: "媒体类型非法", GetAnalystListFailed: "获取研究员列表失败", //用户 TemplateUserNotFound: "临时用户记录不存在", LogoutFailed: "退出登录失败", 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: "用户未开户", SubscribeFailed: "订阅失败", GenerateOrderNoFailed: "生成订单号", IllegalOrderNo: "非法的产品订单号", GetOrderListFailed: "获取产品订单列表失败", //微信 WeChatServerError: "微信服务器发生错误", WechatUserInfoFailed: "获取微信用户信息失败", WeChatResponseError: "解析微信响应数据失败", WeChatCodeEmpty: "微信获取用户信息,code不能为空", WeChatIllegalRequest: "不合法的微信请求", //研报 GetPublishedRandListFailed: "获取已发布研报列表失败", GetPermissionListFailed: "获取品种列表失败", ReportRecordClickCountFailed: "添加点击访问次数失败", MediaRecordClickCountFailed: "添加媒体点击访问次数失败", GetHotRandListFailed: "获取热门研报列表失败", QueryReportPageFailed: "分页查询报告列表失败", SearchReportPageFailed: "分页搜索报告列表失败", GetReportFailed: "获取研报详情失败", GetReportSearchRangeFailed: "设置报告搜索范围失败", SearchKeyEmptyError: "搜索关键字不能为空", ReportRiskLevelUnSet: "报告未设置风险等级", //媒体 MediaFoundFailed: "查询媒体信息失败", GetMediaListFailed: "查询媒体列表失败", GetAnalystMediaListFailed: "查询研究员媒体列表失败", BindMobileFailed: "绑定手机号失败", //商户 ProductInfoError: "获取商品信息失败", IllegalProductId: "非法的产品ID", IllegalProductOrderId: "非法的产品订单ID", //webhook SyncRiskError: "同步风险等级失败", GetCapTokenFailed: "获取cap token失败", GenerateRiskTestTokenFailed: "生成风险测评token失败", //order IllegalOrderStatus: "非法的订单状态", OrderPayTimeoutError: "订单支付超时", } 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) }