errors.go 925 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package imagetype
  2. import (
  3. "net/http"
  4. "github.com/imgproxy/imgproxy/v3/ierrors"
  5. )
  6. type (
  7. TypeDetectionError struct{ error }
  8. UnknownFormatError struct{}
  9. )
  10. func newTypeDetectionError(err error) error {
  11. return ierrors.Wrap(
  12. TypeDetectionError{err},
  13. 1,
  14. ierrors.WithStatusCode(http.StatusUnprocessableEntity),
  15. ierrors.WithPublicMessage("Failed to detect source image type"),
  16. ierrors.WithShouldReport(false),
  17. )
  18. }
  19. func (e TypeDetectionError) Error() string {
  20. return "Failed to detect image type: " + e.error.Error()
  21. }
  22. func (e TypeDetectionError) Unwrap() error { return e.error }
  23. func newUnknownFormatError() error {
  24. return ierrors.Wrap(
  25. UnknownFormatError{},
  26. 1,
  27. ierrors.WithStatusCode(http.StatusUnprocessableEntity),
  28. ierrors.WithPublicMessage("Invalid source image"),
  29. ierrors.WithShouldReport(false),
  30. )
  31. }
  32. func (e UnknownFormatError) Error() string { return "Source image type not supported" }