sso

error_code.go 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package enums
  2. import "SSO/utils"
  3. const ( // ErrorCode
  4. // 登录注册错误 600+
  5. ErrorCodeLoginTimeout = 601
  6. ErrorCodeNotLogin = 602
  7. ErrorCodePermissionDenied = 603
  8. ErrorCodeMobileRegistered = 604
  9. ErrorCodePasswordEmpty = 605
  10. ErrorCodeVerificationCodeWrong = 606
  11. ErrorCodeRegisterFail = 607
  12. ErrorCodeInvalidToken = 608
  13. ErrorCodeAccountOrPasswordWrong = 609
  14. ErrorCodeMissingOrg = 610
  15. ErrorCodeMissingOrgApp = 611
  16. ErrorCodeAccountOrVerCodeWrong = 612
  17. ErrorCodeMobileNotExit = 613
  18. // 数据验证错误 700+
  19. ErrorCodeMobileFormat = 701
  20. ErrorCodeTelphoneFormat = 702
  21. ErrorCodeParamWrong = 703
  22. // 数据库操作错误 800+
  23. ErrorCodeDBCreate = 801
  24. ErrorCodeDBUpdate = 802
  25. ErrorCodeDBDelete = 803
  26. ErrorCodeDBSelectNoResult = 804
  27. ErrorCodeDataException = 805
  28. // 业务逻辑操作错误 900+
  29. ErrorCodeRepeatCreateOrg = 901
  30. ErrorCodeRepeatCreateApp = 902
  31. ErrorCodeNeverCreateTypeApp = 903
  32. ErrorCodeContactSuperAdminCreateTypeApp = 904
  33. )
  34. var ErrCodeMsgs = map[int]string{
  35. // 登录注册错误
  36. ErrorCodeLoginTimeout: "登录超时",
  37. ErrorCodeNotLogin: "未登录",
  38. ErrorCodePermissionDenied: "权限不足",
  39. ErrorCodeMobileRegistered: "手机号已被注册",
  40. ErrorCodePasswordEmpty: "密码为空",
  41. ErrorCodeVerificationCodeWrong: "验证码错误",
  42. ErrorCodeRegisterFail: "注册失败",
  43. ErrorCodeInvalidToken: "令牌无效",
  44. ErrorCodeAccountOrPasswordWrong: "账号或密码错误",
  45. ErrorCodeMissingOrg: "未创建机构",
  46. ErrorCodeMissingOrgApp: "未创建任何应用",
  47. ErrorCodeAccountOrVerCodeWrong: "账号或验证码错误",
  48. ErrorCodeMobileNotExit: "手机号不存在",
  49. // 数据验证错误
  50. ErrorCodeMobileFormat: "手机号格式错误",
  51. ErrorCodeTelphoneFormat: "电话格式错误",
  52. ErrorCodeParamWrong: "参数错误",
  53. // 数据库操作错误
  54. ErrorCodeDBCreate: "数据库创建出错",
  55. ErrorCodeDBUpdate: "数据库更新出错",
  56. ErrorCodeDBDelete: "数据库删除出错",
  57. ErrorCodeDBSelectNoResult: "查询无结果",
  58. ErrorCodeDataException: "数据异常",
  59. // 业务逻辑操作错误
  60. ErrorCodeRepeatCreateOrg: "该账号已创建过机构了",
  61. ErrorCodeRepeatCreateApp: "该账号已创建过此种应用了",
  62. ErrorCodeNeverCreateTypeApp: "未创建此类应用",
  63. ErrorCodeContactSuperAdminCreateTypeApp: "请联系超级管理员开通此种应用",
  64. }
  65. type SGJError struct {
  66. Code int
  67. }
  68. func (e *SGJError) Error() string {
  69. value, ok := ErrCodeMsgs[e.Code]
  70. if ok {
  71. return value
  72. } else {
  73. return "未知错误"
  74. }
  75. }
  76. func MakeSuccessResponseJSON(data map[string]interface{}) map[string]interface{} {
  77. json := make(map[string]interface{})
  78. if data != nil {
  79. json["data"] = data
  80. } else {
  81. json["data"] = make(map[string]interface{})
  82. }
  83. json["state"] = 1
  84. json["code"] = 0
  85. return json
  86. }
  87. func MakeFailResponseJSON(errMsg string, errCode int) map[string]interface{} {
  88. json := make(map[string]interface{})
  89. json["msg"] = errMsg
  90. json["code"] = errCode
  91. json["state"] = 0
  92. return json
  93. }
  94. func MakeFailResponseJSONWithSGJError(err *SGJError) map[string]interface{} {
  95. if err == nil {
  96. utils.WarningLog("MakeFailResponseJSONWithRequestError 参数err 不能为空")
  97. return nil
  98. }
  99. return MakeFailResponseJSON(err.Error(), err.Code)
  100. }
  101. func MakeFailResponseJSONWithSGJErrorCode(code int) map[string]interface{} {
  102. err := &SGJError{Code: code}
  103. return MakeFailResponseJSON(err.Error(), err.Code)
  104. }