error.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.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. ParamsError = status.Error(10002, "参数错误")
  12. NotFoundError = status.Error(10003, "无数据")
  13. DuplicateError = status.Error(10004, "数据重复")
  14. AppKeyNotExistError = status.Error(10005, "AppKey不能为空")
  15. AppKeyNotExist1Error = status.Error(10006, "AppKey不存在")
  16. SignNotExistError = status.Error(10007, "签名不能为空")
  17. SignNotCorrectError = status.Error(10007, "签名错误")
  18. TimeStampNotExistError = status.Error(10007, "时间戳不能为空")
  19. )
  20. func ErrorTransForm(err error) error {
  21. if err == nil {
  22. return nil
  23. }
  24. errStatus := status.Convert(err)
  25. code := errStatus.Code()
  26. if code == codes.Unknown || code == codes.Unavailable || code == codes.Internal {
  27. return SystemError
  28. }
  29. return err
  30. }