errcode.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package response
  2. type ErrCode struct {
  3. Code int
  4. Msg string
  5. }
  6. const (
  7. SUCCESS = 200
  8. AUTHORIZATION_EXPIRED = 401
  9. INVALID_TOKEN = 403
  10. NOT_FOUND = 404
  11. ERROR = 500
  12. PLATFORM_ERROR = 1001 // 第三方错误
  13. REDIS_ERROR = 1002 // 缓存错误
  14. VALIDATOR_ERROR = 1003 // validator校验器错误
  15. DEBUG_ERROR = 1004 // DEBUG的错误信息
  16. DB_ERROR = 1005 // DB异常
  17. PERMISSION_NOT_ALLOWED = 1006
  18. DATA_NOT_FOUND = 9000
  19. NEED_REGIST = 9001
  20. SIGN_ERROR = 9002
  21. ACCOUNT_FORBID = 9003
  22. USER_MOBILE_NOT_BIND = 10002
  23. )
  24. var ErrorCodeMessage = map[int]string{
  25. SUCCESS: "操作成功",
  26. ERROR: "服务器异常",
  27. NOT_FOUND: "无操作权限",
  28. AUTHORIZATION_EXPIRED: "凭证已失效,请重新登录",
  29. INVALID_TOKEN: "凭证无效,请重新登录",
  30. PLATFORM_ERROR: "第三方调用异常",
  31. REDIS_ERROR: "服务器异常[1002]",
  32. VALIDATOR_ERROR: "参数输入错误,请仔细检查",
  33. DEBUG_ERROR: "服务器异常",
  34. DB_ERROR: "服务器异常[1005]",
  35. PERMISSION_NOT_ALLOWED: "您没有权限进行该操作",
  36. DATA_NOT_FOUND: "该项不存在",
  37. NEED_REGIST: "服务人员不存在,请先补充资料",
  38. SIGN_ERROR: "签名错误",
  39. ACCOUNT_FORBID: "您的账号已被禁用",
  40. }
  41. var (
  42. ErrSuccess = &ErrCode{Code: SUCCESS, Msg: ErrorCodeMessage[SUCCESS]}
  43. Err = &ErrCode{Code: ERROR, Msg: ErrorCodeMessage[ERROR]}
  44. ErrNotFound = &ErrCode{Code: NOT_FOUND, Msg: ErrorCodeMessage[NOT_FOUND]}
  45. ErrAuthorizationExpired = &ErrCode{Code: AUTHORIZATION_EXPIRED, Msg: ErrorCodeMessage[AUTHORIZATION_EXPIRED]}
  46. ErrInvalidToken = &ErrCode{Code: INVALID_TOKEN, Msg: ErrorCodeMessage[INVALID_TOKEN]}
  47. ErrPlatform = &ErrCode{Code: PLATFORM_ERROR, Msg: ErrorCodeMessage[PLATFORM_ERROR]}
  48. ErrRedis = &ErrCode{Code: REDIS_ERROR, Msg: ErrorCodeMessage[REDIS_ERROR]}
  49. ErrValidator = &ErrCode{Code: VALIDATOR_ERROR, Msg: ErrorCodeMessage[VALIDATOR_ERROR]}
  50. ErrDebug = &ErrCode{Code: DEBUG_ERROR, Msg: ErrorCodeMessage[DEBUG_ERROR]}
  51. ErrDatabase = &ErrCode{Code: DB_ERROR, Msg: ErrorCodeMessage[DB_ERROR]}
  52. ErrPermissionNotAllowed = &ErrCode{Code: PERMISSION_NOT_ALLOWED, Msg: ErrorCodeMessage[PERMISSION_NOT_ALLOWED]}
  53. ErrDataNotFound = &ErrCode{Code: DATA_NOT_FOUND, Msg: ErrorCodeMessage[DATA_NOT_FOUND]}
  54. ErrNeedRegist = &ErrCode{Code: NEED_REGIST, Msg: ErrorCodeMessage[NEED_REGIST]}
  55. ErrSign = &ErrCode{Code: SIGN_ERROR, Msg: ErrorCodeMessage[SIGN_ERROR]}
  56. ErrAccountForbid = &ErrCode{Code: ACCOUNT_FORBID, Msg: ErrorCodeMessage[ACCOUNT_FORBID]}
  57. )