exc_enums.go 5.7 KB

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