package exception import stringUtils "eta_mini_ht_api/common/utils/string" type EtaError struct { ErrorCode int ErrorMsg string } func (e *EtaError) Error() string { return e.ErrorMsg } const ( // SysErrCode 系统错误 SysErrCode int = iota + 10000 // iota 自动递增,从 1 开始 UnknownError Unauthorized ) // BIZErrCode 业务错误 const ( BIZErrCode int = iota + 20000 // iota 自动递增,从 1 开始 //短信 IllegalCodeLength IllegalPhoneNumber SMSCodeGenerateFailed SendingSMSFailed SMSCodeAlreadySent SMSCodeExpired SMSCodeError AnalystNotFound ) // UserErrCode 用户 const ( UserErrCode int = iota + 30000 // iota 自动递增,从 1 开始 TemplateUserNotFound TemplateUserCreateFailed GenerateTokenFailed JWTTokenDecodeFailed JWTTokenExpired JWTTokenInvalid NotCurrentUserError FeedBackMsgEmpty FeedBackError IllegalFollowType UserFollowAnalystFailed ) // WechatErrCode 微信 const ( WechatErrCode int = iota + 40000 // iota 自动递增,从 1 开始 WeChatServerError WeChatResponseError WechatUserInfoFailed WeChatCodeEmpty WeChatIllegalRequest ) const ( ReportErrCode int = iota + 50000 // iota 自动递增,从 1 开始 GetPublishedRandListFailed GetPermissionListFailed ReportRecordClickCountFailed GetHotRandListFailed QueryReportPageFailed SearchReportPageFailed GetReportFailed SearchKeyEmptyError ) // ErrorMap 用于存储错误码和错误信息的映射 var ErrorMap = map[int]string{ UnknownError: "未知错误", Unauthorized: "用户未授权", IllegalCodeLength: "无效的验证码位数设置", IllegalPhoneNumber: "无效的手机号码", SMSCodeGenerateFailed: "生成手机验证码失败", SendingSMSFailed: "发送手机验证码失败", SMSCodeAlreadySent: "当前手机验证码已发送,请稍后再试", SMSCodeExpired: "验证码已过期", SMSCodeError: "验证码错误", AnalystNotFound: "研究员不存在", //用户 TemplateUserNotFound: "临时用户记录不存在", TemplateUserCreateFailed: "创建临时用户失败", GenerateTokenFailed: "创建token失败", JWTTokenDecodeFailed: "token解析失败", JWTTokenExpired: "token已过期", JWTTokenInvalid: "token无效", NotCurrentUserError: "用户信息不一致,非当前手机用户操作", FeedBackMsgEmpty: "反馈信息不能为空", FeedBackError: "提交反馈信息失败", IllegalFollowType: "无效的关注类型", UserFollowAnalystFailed: "关注研究员失败", //微信 WeChatServerError: "微信服务器发生错误", WechatUserInfoFailed: "获取微信用户信息失败", WeChatResponseError: "解析微信响应数据失败", WeChatCodeEmpty: "微信获取用户信息,code不能为空", WeChatIllegalRequest: "不合法的微信请求", //研报 GetPublishedRandListFailed: "获取已发布研报列表失败", GetPermissionListFailed: "获取品种列表失败", ReportRecordClickCountFailed: "添加点击访问次数失败", GetHotRandListFailed: "获取热门研报列表失败", QueryReportPageFailed: "分页查询报告列表失败", SearchReportPageFailed: "分页搜索报告列表失败", GetReportFailed: "获取研报详情失败", SearchKeyEmptyError: "搜索关键字不能为空", } func Equals(code int, message string) bool { if stringUtils.IsEmptyOrNil(message) { return false } return ErrorMap[code] == message } func GetMsg(code int) string { return ErrorMap[code] } func newException(code int, msg string) error { return &EtaError{ ErrorCode: code, ErrorMsg: msg, } } func New(code int) *EtaError { err := ErrorMap[code] if stringUtils.IsBlank(err) { return newException(UnknownError, ErrorMap[UnknownError]).(*EtaError) } return newException(code, err).(*EtaError) }