errors.go 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package errors
  2. import (
  3. "encoding/json"
  4. "gd_management_gateway/common.in/jsonrpc2"
  5. )
  6. var (
  7. // 通用错误
  8. SystemError = jsonrpc2.NewJsonError(10001, "系统错误")
  9. BadParaFormat = jsonrpc2.NewJsonError(10002, "请求参数格式不对")
  10. ServiceError = jsonrpc2.NewJsonError(10003, "内部服务错误")
  11. NoAuthAccess = jsonrpc2.NewJsonError(10004, "无访问权限")
  12. IpNoAuthAccess = jsonrpc2.NewJsonError(10005, "IP无访问权限")
  13. UserTokenillegality = jsonrpc2.NewJsonError(10006, "用户Token非法错误")
  14. UserTokenExpire = jsonrpc2.NewJsonError(10007, "用户Token已过期")
  15. AuthNotAllow = jsonrpc2.NewJsonError(10008, "用户权限不足")
  16. // 业务错误
  17. ArgsError = jsonrpc2.NewJsonError(20001, "参数错误")
  18. DataBaseError = jsonrpc2.NewJsonError(20002, "数据库操作失败")
  19. VendorError = jsonrpc2.NewJsonError(20003, "第三方发生错误")
  20. DataBaseNoRecord = jsonrpc2.NewJsonError(20004, "没有找到相关记录")
  21. // 01 user 02 vehicle 03 service
  22. // 业务错误-01 user
  23. AppKeyError = jsonrpc2.NewJsonError(20101, "AppKey错误")
  24. AppKeyExpired = jsonrpc2.NewJsonError(20102, "AppKey过期")
  25. SignError = jsonrpc2.NewJsonError(20103, "签名异常")
  26. TokenExpired = jsonrpc2.NewJsonError(20104, "token已过期")
  27. ApiUseExpired = jsonrpc2.NewJsonError(20105, "API接口使用已到期")
  28. BeyondRequestLimit = jsonrpc2.NewJsonError(20106, "超出请求次数次数限制")
  29. BeyondRequestByDayLimit = jsonrpc2.NewJsonError(20107, "超出本日请求次数次数限制")
  30. BeyondRequestByWeekLimit = jsonrpc2.NewJsonError(20108, "超出本周请求次数次数限制")
  31. BeyondRequestByMonthLimit = jsonrpc2.NewJsonError(20109, "超出本月请求次数次数限制")
  32. BeyondRequestByYearLimit = jsonrpc2.NewJsonError(20110, "超出本年请求次数次数限制")
  33. AccountLock = jsonrpc2.NewJsonError(20111, "账号登录频繁,请稍后再试")
  34. PasswordError = jsonrpc2.NewJsonError(20112, "密码最低长度8位,至少包含两种字符(字母, 数字)")
  35. // 业务错误-02 vehicle
  36. VinPlateError = jsonrpc2.NewJsonError(20201, "vin码和车牌号码不匹配")
  37. // 业务错误-03 service
  38. ViolationCityMaintain = jsonrpc2.NewJsonError(20301, "查询的城市正在维护中")
  39. C300CityNotSupport = jsonrpc2.NewJsonError(20302, "车牌城市不支持估值查询")
  40. AnnalExamNotStationsForCity = jsonrpc2.NewJsonError(20303, "年检城市没有检测站")
  41. ServiceNoRecordError = jsonrpc2.NewJsonError(20304, "没有该服务类型")
  42. OrderExistError = jsonrpc2.NewJsonError(20305, "不能重复创建订单")
  43. VehiclePlateNumberError = jsonrpc2.NewJsonError(20306, "车牌号有误")
  44. VehicleEnginNoError = jsonrpc2.NewJsonError(20307, "发动机号有误")
  45. VehicleVinError = jsonrpc2.NewJsonError(20308, "车架号有误")
  46. VehicleTypeNotSupport = jsonrpc2.NewJsonError(20309, "不支持的车辆类型")
  47. VehicleInfoNotExist = jsonrpc2.NewJsonError(20310, "车辆信息不存在")
  48. ViolationQueryNotSupport = jsonrpc2.NewJsonError(20311, "查询的省市未开通")
  49. ViolationQueryNotSupportOtherPlace = jsonrpc2.NewJsonError(20312, "该省份不支持异地车辆违法查询")
  50. FileErr = jsonrpc2.NewJsonError(20313, "文件不能为空")
  51. ExtErr = jsonrpc2.NewJsonError(20314, "后缀名不符合上传要求")
  52. FileTypeErr = jsonrpc2.NewJsonError(20315, "文件类型错误")
  53. FileSizeErr = jsonrpc2.NewJsonError(20316, "文件太大")
  54. FileOpenFailed = jsonrpc2.NewJsonError(20317, "文件打开失败")
  55. ExportPdfFailed = jsonrpc2.NewJsonError(20318, "pdf 生成失败")
  56. OrderStatusNoSupport = jsonrpc2.NewJsonError(20319, "不支持的订单状态")
  57. )
  58. func ErrorTransform(errReturn error) error {
  59. var e jsonrpc2.Error
  60. err := json.Unmarshal([]byte(errReturn.Error()), &e)
  61. if err != nil {
  62. return ServiceError
  63. }
  64. /*switch e.Code {
  65. case 20003:
  66. return ServiceError
  67. default:
  68. return errReturn
  69. }*/
  70. return errReturn
  71. }