errors.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 (e UnknownOptionError) Error() string { return string(e) }
  32. func newOptionArgumentError(format string, args ...interface{}) error {
  33. return ierrors.Wrap(
  34. OptionArgumentError(fmt.Sprintf(format, args...)),
  35. 1,
  36. ierrors.WithStatusCode(http.StatusNotFound),
  37. ierrors.WithPublicMessage("Invalid URL"),
  38. ierrors.WithShouldReport(false),
  39. )
  40. }
  41. func (e OptionArgumentError) Error() string { return string(e) }