error.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package errors
  4. import (
  5. "google.golang.org/grpc/codes"
  6. "google.golang.org/grpc/status"
  7. )
  8. var (
  9. // 通用错误
  10. SystemError = status.Error(10001, "系统错误")
  11. ServiceError = status.Error(10002, "内部服务错误")
  12. ParamsError = status.Error(10003, "参数错误")
  13. DataBaseError = status.Error(10004, "数据库错误")
  14. RedisError = status.Error(10005, "Redis错误")
  15. OssError = status.Error(10006, "对象存储服务错误")
  16. OssObjNotExist = status.Error(10006, "文件不存在")
  17. OssFileTooBig = status.Error(10006, "文件不能超过10M")
  18. NoTokenError = status.Error(10008, "没有token")
  19. TokenExpiredError = status.Error(10009, "token已过期")
  20. TokenFailedError = status.Error(10010, "token错误")
  21. PermissionError = status.Error(10011, "权限不足")
  22. PermissionErrorNoRouter = status.Error(10012, "权限不足未设置该路由")
  23. ErrRecordNotFound = status.Error(10012, "数据不存在")
  24. PermissionChangedError = status.Error(19999, "权限变动,请重新获取")
  25. )
  26. func ErrorTransForm(err error) error {
  27. if err == nil {
  28. return nil
  29. }
  30. errStatus := status.Convert(err)
  31. code := errStatus.Code()
  32. //msg := errStatus.Message()
  33. if code == codes.Unknown {
  34. return ServiceError
  35. }
  36. return err
  37. }