errors.go 621 B

123456789101112131415161718192021222324252627282930313233
  1. package redis
  2. import (
  3. "strings"
  4. pkgerr "github.com/pkg/errors"
  5. )
  6. func formatErr(err error) string {
  7. e := pkgerr.Cause(err)
  8. switch e {
  9. case ErrNil, nil:
  10. return ""
  11. default:
  12. es := e.Error()
  13. switch {
  14. case strings.HasPrefix(es, "read"):
  15. return "read timeout"
  16. case strings.HasPrefix(es, "dial"):
  17. return "dial timeout"
  18. case strings.HasPrefix(es, "write"):
  19. return "write timeout"
  20. case strings.Contains(es, "EOF"):
  21. return "eof"
  22. case strings.Contains(es, "reset"):
  23. return "reset"
  24. case strings.Contains(es, "broken"):
  25. return "broken pipe"
  26. default:
  27. return "unexpected err"
  28. }
  29. }
  30. }