exc_enums.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package exception
  2. import stringUtils "eta/eta_mini_ht_api/common/utils/string"
  3. type EtaError struct {
  4. ErrorCode int
  5. ErrorMsg string
  6. Exception string
  7. }
  8. func (e *EtaError) Error() string {
  9. return e.ErrorMsg
  10. }
  11. const (
  12. // SysErrCode 系统错误
  13. SysErrCode int = iota + 10000 // iota 自动递增,从 1 开始
  14. UnknownError
  15. Unauthorized
  16. SysError
  17. QueryRiskMappingError
  18. IllegalConfigType
  19. GetConfigValueFailed
  20. )
  21. // BIZErrCode 业务错误
  22. const (
  23. BIZErrCode int = iota + 20000 // iota 自动递增,从 1 开始
  24. //短信
  25. IllegalCodeLength
  26. IllegalPhoneNumber
  27. SMSCodeGenerateFailed
  28. SendingSMSFailed
  29. SMSCodeAlreadySent
  30. SMSCodeExpired
  31. SMSCodeError
  32. GetAreaCodesFailed
  33. AnalystNotFound
  34. IllegalAreaCode
  35. MediaTypeError
  36. GetAnalystListFailed
  37. BatchFollowingAnalystFailed
  38. )
  39. // UserErrCode 用户
  40. const (
  41. UserErrCode int = iota + 30000 // iota 自动递增,从 1 开始
  42. TemplateUserNotFound
  43. TemplateUserFoundFailed
  44. IllegalTemplateUserId
  45. TemplateUserCreateFailed
  46. TemplateUserBindFailed
  47. GenerateTokenFailed
  48. JWTTokenDecodeFailed
  49. LoginFailed
  50. LogoutFailed
  51. JWTTokenExpired
  52. JWTTokenInvalid
  53. NotCurrentUserError
  54. FeedBackMsgEmpty
  55. FeedBackError
  56. IllegalFollowType
  57. UserFollowAnalystFailed
  58. GetNoticeFileError
  59. GetDisclaimerFileError
  60. AnalystNameEmptyError
  61. IllegalAnalystIdError
  62. GetFollowingAnalystListFailed
  63. TransferFollowingAnalystListFailed
  64. GetUserUnReadMsgFailed
  65. IllegalMessageId
  66. IllegalAnalystId
  67. ReadMessageFailed
  68. BindMobileFailed
  69. CheckFollowStatusByNamesFailed
  70. RiskUnTestError
  71. RiskExpiredError
  72. RiskUnMatchError
  73. OfficialUserFoundError
  74. OfficialUserNotFound
  75. IllegalAccountStatus
  76. AccountNotOpen
  77. IDExpired
  78. SubscribeFailed
  79. DuplicateSubscribe
  80. GenerateOrderNoFailed
  81. IllegalOrderNo
  82. GetOrderListFailed
  83. GetOrderDetailFailed
  84. CloseOrderFailed
  85. GetBookMarkListFailed
  86. )
  87. // WechatErrCode 微信
  88. const (
  89. WechatErrCode int = iota + 40000 // iota 自动递增,从 1 开始
  90. WeChatServerError
  91. WeChatResponseError
  92. WechatUserInfoFailed
  93. WeChatCodeEmpty
  94. WeChatIllegalRequest
  95. )
  96. const (
  97. ReportErrCode int = iota + 50000 // iota 自动递增,从 1 开始
  98. GetPublishedRandListFailed
  99. GetPermissionListFailed
  100. ReportRecordClickCountFailed
  101. MediaRecordClickCountFailed
  102. GetHotRandListFailed
  103. QueryReportPageFailed
  104. SearchReportPageFailed
  105. GetReportFailed
  106. GetReportSearchRangeFailed
  107. SearchKeyEmptyError
  108. ReportRiskLevelUnSet
  109. ReportDeleted
  110. )
  111. const (
  112. MediaErrCode int = iota + 60000 // iota 自动递增,从 1 开始
  113. MediaFoundFailed
  114. GetMediaListFailed
  115. GetAnalystMediaListFailed
  116. ChartImageEmptyError
  117. IllegalChartId
  118. UpdateChartImageFailed
  119. )
  120. const (
  121. MerchantErrCode int = iota + 70000
  122. ProductInfoError
  123. IllegalProductId
  124. IllegalProductOrderId
  125. MerchantInfoNotConfig
  126. GetProductListFailed
  127. IllegalProductType
  128. )
  129. const (
  130. WebhookErrCode int = iota + 80000
  131. SyncRiskError
  132. GetCapTokenFailed
  133. GetCustomerRiskInfoFailed
  134. GenerateRiskTestTokenFailed
  135. )
  136. const (
  137. OrderErrorCode int = iota + 90000
  138. IllegalOrderStatus
  139. OrderPayTimeoutError
  140. PayTradeOrderFailed
  141. )
  142. const (
  143. ProductErrorCode int = iota + 100000
  144. ProductOffSale
  145. ProductNotFound
  146. ProductTypeError
  147. ProductGetFailed
  148. )
  149. const (
  150. PaymentErrCode int = iota + 110000
  151. CreatePaymentOrderFailed
  152. PaymentProcessingError
  153. PaymentDoneError
  154. RefundDealFail
  155. )
  156. const (
  157. BookMarkErrCode int = iota + 120000 // iota 自动递增,从 1 开始
  158. IllegalSourceType
  159. IllegalSearchKeyword
  160. IllegalSourceId
  161. BookMarkFailed
  162. BookMarkListFailed
  163. )
  164. // ErrorMap 用于存储错误码和错误信息的映射
  165. var ErrorMap = map[int]string{
  166. SysError: "系统异常",
  167. UnknownError: "未知错误",
  168. Unauthorized: "用户未授权",
  169. QueryRiskMappingError: "查询风险等级映射设置错误",
  170. IllegalCodeLength: "无效的验证码位数设置",
  171. IllegalPhoneNumber: "无效的手机号码",
  172. SMSCodeGenerateFailed: "生成手机验证码失败",
  173. SendingSMSFailed: "发送手机验证码失败",
  174. SMSCodeAlreadySent: "当前手机验证码已发送,请稍后再试",
  175. SMSCodeExpired: "验证码已过期",
  176. SMSCodeError: "验证码错误",
  177. AnalystNotFound: "研究员不存在",
  178. GetAreaCodesFailed: "获取手机区号失败",
  179. IllegalAreaCode: "无效的区号",
  180. MediaTypeError: "媒体类型非法",
  181. GetAnalystListFailed: "获取研究员列表失败",
  182. IllegalConfigType: "不合法的配置项值类型",
  183. GetConfigValueFailed: "配置获取失败",
  184. //用户
  185. TemplateUserNotFound: "临时用户记录不存在",
  186. LogoutFailed: "退出登录失败",
  187. LoginFailed: "登录失败",
  188. TemplateUserFoundFailed: "查询临时用户表失败",
  189. IllegalTemplateUserId: "不合法的临时用户ID",
  190. TemplateUserCreateFailed: "创建临时用户失败",
  191. TemplateUserBindFailed: "临时用户绑定小程序失败",
  192. GenerateTokenFailed: "创建token失败",
  193. JWTTokenDecodeFailed: "token解析失败",
  194. JWTTokenExpired: "token已过期",
  195. JWTTokenInvalid: "token无效",
  196. NotCurrentUserError: "用户信息不一致,非当前手机用户操作",
  197. FeedBackMsgEmpty: "反馈信息不能为空",
  198. FeedBackError: "提交反馈信息失败",
  199. IllegalFollowType: "无效的关注类型",
  200. UserFollowAnalystFailed: "关注研究员失败",
  201. GetNoticeFileError: "获取注册须知失败",
  202. GetDisclaimerFileError: "获取免责声明失败",
  203. AnalystNameEmptyError: "研究员姓名不能为空",
  204. GetFollowingAnalystListFailed: "获取关注研究员列表失败",
  205. TransferFollowingAnalystListFailed: "转换关注研究员列表失败",
  206. GetUserUnReadMsgFailed: "获取未读消息列表失败",
  207. IllegalMessageId: "非法的消息ID",
  208. ReadMessageFailed: "已读消息失败",
  209. IllegalAnalystId: "研究员Id非法",
  210. CheckFollowStatusByNamesFailed: "获取关注猪状态失败",
  211. BatchFollowingAnalystFailed: "批量关注研究员列表失败",
  212. RiskUnTestError: "客户未做风险测评",
  213. RiskExpiredError: "客户风险测评已过期",
  214. RiskUnMatchError: "客户风险测评不匹配",
  215. OfficialUserFoundError: "获取正式用户信息失败",
  216. OfficialUserNotFound: "用户未开户",
  217. IllegalAccountStatus: "非法的开户状态",
  218. SubscribeFailed: "订阅失败",
  219. DuplicateSubscribe: "重复订阅",
  220. GenerateOrderNoFailed: "生成订单号",
  221. IllegalOrderNo: "非法的商品订单号",
  222. GetOrderListFailed: "获取产品订单列表失败",
  223. GetOrderDetailFailed: "获取订单详情失败",
  224. CloseOrderFailed: "关闭订单失败",
  225. GetBookMarkListFailed: "获取收藏列表失败",
  226. //微信
  227. WeChatServerError: "微信服务器发生错误",
  228. WechatUserInfoFailed: "获取微信用户信息失败",
  229. WeChatResponseError: "解析微信响应数据失败",
  230. WeChatCodeEmpty: "微信获取用户信息,code不能为空",
  231. WeChatIllegalRequest: "不合法的微信请求",
  232. //研报
  233. GetPublishedRandListFailed: "获取已发布研报列表失败",
  234. GetPermissionListFailed: "获取品种列表失败",
  235. ReportRecordClickCountFailed: "添加点击访问次数失败",
  236. MediaRecordClickCountFailed: "添加媒体点击访问次数失败",
  237. GetHotRandListFailed: "获取热门研报列表失败",
  238. QueryReportPageFailed: "分页查询报告列表失败",
  239. SearchReportPageFailed: "分页搜索报告列表失败",
  240. GetReportFailed: "获取研报详情失败",
  241. ReportDeleted: "研报已删除",
  242. GetReportSearchRangeFailed: "设置报告搜索范围失败",
  243. SearchKeyEmptyError: "搜索关键字不能为空",
  244. ReportRiskLevelUnSet: "报告未设置风险等级",
  245. //媒体
  246. MediaFoundFailed: "查询媒体信息失败",
  247. GetMediaListFailed: "查询媒体列表失败",
  248. GetAnalystMediaListFailed: "查询研究员媒体列表失败",
  249. BindMobileFailed: "绑定手机号失败",
  250. ChartImageEmptyError: "图表缩略图url不能为空",
  251. IllegalChartId: "非法的图表ID",
  252. UpdateChartImageFailed: "更新图表缩略图失败",
  253. //商户
  254. ProductInfoError: "获取商品信息失败",
  255. IllegalProductId: "非法的产品ID",
  256. IllegalProductOrderId: "非法的产品订单ID",
  257. MerchantInfoNotConfig: "商户信息未配置",
  258. GetProductListFailed: "获取产品列表失败",
  259. IllegalProductType: "非法的产品类型",
  260. //webhook
  261. SyncRiskError: "同步风险等级失败",
  262. GetCapTokenFailed: "获取cap token失败",
  263. GenerateRiskTestTokenFailed: "生成风险测评token失败",
  264. GetCustomerRiskInfoFailed: "查询客户风险信息失败",
  265. //order
  266. IllegalOrderStatus: "非法的订单状态",
  267. OrderPayTimeoutError: "订单支付超时",
  268. PayTradeOrderFailed: "订单支付失败",
  269. //product
  270. ProductOffSale: "商品已下架",
  271. ProductTypeError: "非法的产品类型",
  272. ProductGetFailed: "获取商品信息失败",
  273. ProductNotFound: "商品不存在",
  274. //支付
  275. CreatePaymentOrderFailed: "创建支付订单失败",
  276. PaymentProcessingError: "支付订单处理中",
  277. PaymentDoneError: "订单已完成支付",
  278. RefundDealFail: "处理退款应答失败",
  279. //收藏
  280. IllegalSourceType: "非法的资源类型",
  281. IllegalSourceId: "非法的资源ID",
  282. BookMarkFailed: "收藏失败",
  283. BookMarkListFailed: "获取收藏列表失败",
  284. IllegalSearchKeyword: "搜索关键字不能为空",
  285. }
  286. func Equals(code int, message string) bool {
  287. if stringUtils.IsEmptyOrNil(message) {
  288. return false
  289. }
  290. return ErrorMap[code] == message
  291. }
  292. func GetMsg(code int) string {
  293. return ErrorMap[code]
  294. }
  295. func newException(code int, msg string) error {
  296. return &EtaError{
  297. ErrorCode: code,
  298. ErrorMsg: msg,
  299. }
  300. }
  301. func newExceptionWithOrgMsg(code int, msg string, exception string) error {
  302. return &EtaError{
  303. ErrorCode: code,
  304. ErrorMsg: msg,
  305. Exception: exception,
  306. }
  307. }
  308. func New(code int) *EtaError {
  309. err := ErrorMap[code]
  310. if stringUtils.IsBlank(err) {
  311. return newException(UnknownError, ErrorMap[UnknownError]).(*EtaError)
  312. }
  313. return newException(code, err).(*EtaError)
  314. }
  315. func NewWithException(code int, exception string) *EtaError {
  316. err := ErrorMap[code]
  317. if stringUtils.IsBlank(err) {
  318. return newException(UnknownError, ErrorMap[UnknownError]).(*EtaError)
  319. }
  320. return newExceptionWithOrgMsg(code, err, exception).(*EtaError)
  321. }