exc_enums.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. }
  7. func (e *EtaError) Error() string {
  8. return e.ErrorMsg
  9. }
  10. const (
  11. // SysErrCode 系统错误
  12. SysErrCode int = iota + 10000 // iota 自动递增,从 1 开始
  13. UnknownError
  14. Unauthorized
  15. )
  16. // BIZErrCode 业务错误
  17. const (
  18. BIZErrCode int = iota + 20000 // iota 自动递增,从 1 开始
  19. //短信
  20. IllegalCodeLength
  21. IllegalPhoneNumber
  22. SMSCodeGenerateFailed
  23. SendingSMSFailed
  24. SMSCodeAlreadySent
  25. SMSCodeExpired
  26. SMSCodeError
  27. GetAreaCodesFailed
  28. AnalystNotFound
  29. IllegalAreaCode
  30. MediaTypeError
  31. GetAnalystListFailed
  32. BatchFollowingAnalystFailed
  33. )
  34. // UserErrCode 用户
  35. const (
  36. UserErrCode int = iota + 30000 // iota 自动递增,从 1 开始
  37. TemplateUserNotFound
  38. TemplateUserFoundFailed
  39. TemplateUserCreateFailed
  40. TemplateUserBindFailed
  41. GenerateTokenFailed
  42. JWTTokenDecodeFailed
  43. LogoutFailed
  44. JWTTokenExpired
  45. JWTTokenInvalid
  46. NotCurrentUserError
  47. FeedBackMsgEmpty
  48. FeedBackError
  49. IllegalFollowType
  50. UserFollowAnalystFailed
  51. GetNoticeFileError
  52. GetDisclaimerFileError
  53. AnalystNameEmptyError
  54. IllegalAnalystIdError
  55. GetFollowingAnalystListFailed
  56. TransferFollowingAnalystListFailed
  57. GetUserUnReadMsgFailed
  58. IllegalMessageId
  59. IllegalAnalystId
  60. ReadMessageFailed
  61. BindMobileFailed
  62. CheckFollowStatusByNamesFailed
  63. RiskUnTestError
  64. RiskExpiredError
  65. )
  66. // WechatErrCode 微信
  67. const (
  68. WechatErrCode int = iota + 40000 // iota 自动递增,从 1 开始
  69. WeChatServerError
  70. WeChatResponseError
  71. WechatUserInfoFailed
  72. WeChatCodeEmpty
  73. WeChatIllegalRequest
  74. )
  75. const (
  76. ReportErrCode int = iota + 50000 // iota 自动递增,从 1 开始
  77. GetPublishedRandListFailed
  78. GetPermissionListFailed
  79. ReportRecordClickCountFailed
  80. MediaRecordClickCountFailed
  81. GetHotRandListFailed
  82. QueryReportPageFailed
  83. SearchReportPageFailed
  84. GetReportFailed
  85. GetReportSearchRangeFailed
  86. SearchKeyEmptyError
  87. )
  88. const (
  89. MediaErrCode int = iota + 60000 // iota 自动递增,从 1 开始
  90. MediaFoundFailed
  91. GetMediaListFailed
  92. GetAnalystMediaListFailed
  93. )
  94. // ErrorMap 用于存储错误码和错误信息的映射
  95. var ErrorMap = map[int]string{
  96. UnknownError: "未知错误",
  97. Unauthorized: "用户未授权",
  98. IllegalCodeLength: "无效的验证码位数设置",
  99. IllegalPhoneNumber: "无效的手机号码",
  100. SMSCodeGenerateFailed: "生成手机验证码失败",
  101. SendingSMSFailed: "发送手机验证码失败",
  102. SMSCodeAlreadySent: "当前手机验证码已发送,请稍后再试",
  103. SMSCodeExpired: "验证码已过期",
  104. SMSCodeError: "验证码错误",
  105. AnalystNotFound: "研究员不存在",
  106. GetAreaCodesFailed: "获取手机区号失败",
  107. IllegalAreaCode: "无效的区号",
  108. MediaTypeError: "媒体类型非法",
  109. GetAnalystListFailed: "获取研究员列表失败",
  110. //用户
  111. TemplateUserNotFound: "临时用户记录不存在",
  112. LogoutFailed: "退出登录失败",
  113. TemplateUserFoundFailed: "查询临时用户表失败",
  114. TemplateUserCreateFailed: "创建临时用户失败",
  115. TemplateUserBindFailed: "临时用户绑定小程序失败",
  116. GenerateTokenFailed: "创建token失败",
  117. JWTTokenDecodeFailed: "token解析失败",
  118. JWTTokenExpired: "token已过期",
  119. JWTTokenInvalid: "token无效",
  120. NotCurrentUserError: "用户信息不一致,非当前手机用户操作",
  121. FeedBackMsgEmpty: "反馈信息不能为空",
  122. FeedBackError: "提交反馈信息失败",
  123. IllegalFollowType: "无效的关注类型",
  124. UserFollowAnalystFailed: "关注研究员失败",
  125. GetNoticeFileError: "获取注册须知失败",
  126. GetDisclaimerFileError: "获取免责声明失败",
  127. AnalystNameEmptyError: "研究员姓名不能为空",
  128. GetFollowingAnalystListFailed: "获取关注研究员列表失败",
  129. TransferFollowingAnalystListFailed: "转换关注研究员列表失败",
  130. GetUserUnReadMsgFailed: "获取未读消息列表失败",
  131. IllegalMessageId: "非法的消息ID",
  132. ReadMessageFailed: "已读消息失败",
  133. IllegalAnalystId: "研究员Id非法",
  134. CheckFollowStatusByNamesFailed: "获取关注猪状态失败",
  135. BatchFollowingAnalystFailed: "批量关注研究员列表失败",
  136. RiskUnTestError: "客户未做风险测评",
  137. RiskExpiredError: "客户风险测评已过期",
  138. //微信
  139. WeChatServerError: "微信服务器发生错误",
  140. WechatUserInfoFailed: "获取微信用户信息失败",
  141. WeChatResponseError: "解析微信响应数据失败",
  142. WeChatCodeEmpty: "微信获取用户信息,code不能为空",
  143. WeChatIllegalRequest: "不合法的微信请求",
  144. //研报
  145. GetPublishedRandListFailed: "获取已发布研报列表失败",
  146. GetPermissionListFailed: "获取品种列表失败",
  147. ReportRecordClickCountFailed: "添加点击访问次数失败",
  148. MediaRecordClickCountFailed: "添加媒体点击访问次数失败",
  149. GetHotRandListFailed: "获取热门研报列表失败",
  150. QueryReportPageFailed: "分页查询报告列表失败",
  151. SearchReportPageFailed: "分页搜索报告列表失败",
  152. GetReportFailed: "获取研报详情失败",
  153. GetReportSearchRangeFailed: "设置报告搜索范围失败",
  154. SearchKeyEmptyError: "搜索关键字不能为空",
  155. //媒体
  156. MediaFoundFailed: "查询媒体信息失败",
  157. GetMediaListFailed: "查询媒体列表失败",
  158. GetAnalystMediaListFailed: "查询研究员媒体列表失败",
  159. BindMobileFailed: "绑定手机号失败",
  160. }
  161. func Equals(code int, message string) bool {
  162. if stringUtils.IsEmptyOrNil(message) {
  163. return false
  164. }
  165. return ErrorMap[code] == message
  166. }
  167. func GetMsg(code int) string {
  168. return ErrorMap[code]
  169. }
  170. func newException(code int, msg string) error {
  171. return &EtaError{
  172. ErrorCode: code,
  173. ErrorMsg: msg,
  174. }
  175. }
  176. func New(code int) *EtaError {
  177. err := ErrorMap[code]
  178. if stringUtils.IsBlank(err) {
  179. return newException(UnknownError, ErrorMap[UnknownError]).(*EtaError)
  180. }
  181. return newException(code, err).(*EtaError)
  182. }