error.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. ErrRecordNotFound = status.Error(10005, "查无记录")
  15. NoTokenError = status.Error(10008, "没有token")
  16. TokenExpiredError = status.Error(10009, "token已过期")
  17. TokenFailedError = status.Error(10010, "token错误")
  18. PermissionError = status.Error(10011, "权限不足")
  19. UserNotExist = status.Error(20001, "用户不存在")
  20. PasswordError = status.Error(20002, "密码错误")
  21. UserNotEffective = status.Error(20003, "账户不在有效期内")
  22. UserWrong = status.Error(20004, "账户非法")
  23. )
  24. func ErrorTransForm(err error) error {
  25. if err == nil {
  26. return nil
  27. }
  28. errStatus := status.Convert(err)
  29. code := errStatus.Code()
  30. //msg := errStatus.Message()
  31. if code == codes.Unknown {
  32. return ServiceError
  33. }
  34. return err
  35. }