exc_enums.go 5.9 KB

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