1
0

errors.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package security
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/imgproxy/imgproxy/v3/ierrors"
  6. )
  7. type (
  8. SignatureError string
  9. ImageResolutionError string
  10. SourceURLError string
  11. )
  12. func newSignatureError(msg string) error {
  13. return ierrors.Wrap(
  14. SignatureError(msg),
  15. 1,
  16. ierrors.WithStatusCode(http.StatusForbidden),
  17. ierrors.WithPublicMessage("Forbidden"),
  18. ierrors.WithShouldReport(false),
  19. )
  20. }
  21. func (e SignatureError) Error() string { return string(e) }
  22. func newImageResolutionError(msg string) error {
  23. return ierrors.Wrap(
  24. ImageResolutionError(msg),
  25. 1,
  26. ierrors.WithStatusCode(http.StatusUnprocessableEntity),
  27. ierrors.WithPublicMessage("Invalid source image"),
  28. ierrors.WithShouldReport(false),
  29. )
  30. }
  31. func (e ImageResolutionError) Error() string { return string(e) }
  32. func newSourceURLError(imageURL string) error {
  33. return ierrors.Wrap(
  34. SourceURLError(fmt.Sprintf("Source URL is not allowed: %s", imageURL)),
  35. 1,
  36. ierrors.WithStatusCode(http.StatusNotFound),
  37. ierrors.WithPublicMessage("Invalid source URL"),
  38. ierrors.WithShouldReport(false),
  39. )
  40. }
  41. func (e SourceURLError) Error() string { return string(e) }