errors.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package options
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/imgproxy/imgproxy/v3/ierrors"
  6. )
  7. type (
  8. InvalidURLError string
  9. UnknownOptionError string
  10. OptionArgumentError string
  11. )
  12. func newInvalidURLError(format string, args ...interface{}) error {
  13. return ierrors.Wrap(
  14. InvalidURLError(fmt.Sprintf(format, args...)),
  15. 1,
  16. ierrors.WithStatusCode(http.StatusNotFound),
  17. ierrors.WithPublicMessage("Invalid URL"),
  18. ierrors.WithShouldReport(false),
  19. )
  20. }
  21. func (e InvalidURLError) Error() string { return string(e) }
  22. func newUnknownOptionError(kind, opt string) error {
  23. return ierrors.Wrap(
  24. UnknownOptionError(fmt.Sprintf("Unknown %s option %s", kind, opt)),
  25. 1,
  26. ierrors.WithStatusCode(http.StatusNotFound),
  27. ierrors.WithPublicMessage("Invalid URL"),
  28. ierrors.WithShouldReport(false),
  29. )
  30. }
  31. func newForbiddenOptionError(kind, opt string) error {
  32. return ierrors.Wrap(
  33. UnknownOptionError(fmt.Sprintf("Forbidden %s option %s", kind, opt)),
  34. 1,
  35. ierrors.WithStatusCode(http.StatusNotFound),
  36. ierrors.WithPublicMessage("Invalid URL"),
  37. ierrors.WithShouldReport(false),
  38. )
  39. }
  40. func (e UnknownOptionError) Error() string { return string(e) }
  41. func newOptionArgumentError(format string, args ...interface{}) error {
  42. return ierrors.Wrap(
  43. OptionArgumentError(fmt.Sprintf(format, args...)),
  44. 1,
  45. ierrors.WithStatusCode(http.StatusNotFound),
  46. ierrors.WithPublicMessage("Invalid URL"),
  47. ierrors.WithShouldReport(false),
  48. )
  49. }
  50. func (e OptionArgumentError) Error() string { return string(e) }