error.go 922 B

12345678910111213141516171819202122232425262728293031323334353637
  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. KeyError = status.Error(10005, "AppKey错误")
  15. NoDeleteError = status.Error(10006, "无待删除员工")
  16. NoDownloadError = status.Error(10007, "无待下发员工")
  17. SnNotExistError = status.Error(10008, "设备序列号不存在")
  18. )
  19. func ErrorTransForm(err error) error {
  20. if err == nil {
  21. return nil
  22. }
  23. errStatus := status.Convert(err)
  24. code := errStatus.Code()
  25. //msg := errStatus.Message()
  26. if code == codes.Unknown {
  27. return ServiceError
  28. }
  29. return err
  30. }