exc_enums.go 11 KB

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