exc_enums.go 11 KB

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