🐛 Return 400 instead of 500 when ImageMagick fails on invalid images (#10643)

When ImageMagick fails to process an uploaded image (e.g., corrupted PNG
with invalid IHDR data), the backend was raising :type :internal with
:code :imagemagick-error, which mapped to HTTP 500. The frontend treated
this as a server error and displayed the full error page.

Changed exec-magick! to raise :type :validation with :code :invalid-image
instead. This flows through the existing :invalid-image handler in
errors.clj which returns HTTP 400. The frontend's handle-media-error and
process-error now catch this code and show a notification banner.

AI-assisted-by: qwen3.7-plus
This commit is contained in:
Andrey Antukh 2026-07-20 11:56:07 +02:00 committed by GitHub
parent fc6b3ee7f0
commit 26c4ec18fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View File

@ -184,8 +184,8 @@
:env (get-imagemagick-env)
:timeout 60)]
(when (not= 0 (:exit result))
(ex/raise :type :internal
:code :imagemagick-error
(ex/raise :type :validation
:code :invalid-image
:hint (str "ImageMagick command failed: " (:err result))
:cmd cmd
:exit (:exit result)))

View File

@ -67,8 +67,8 @@
(t/is false "should have thrown")
(catch Exception e
(let [data (ex-data e)]
;; Could be validation or imagemagick-error depending on what magick does
(t/is (contains? #{:validation :internal} (:type data)))))
(t/is (= :validation (:type data)))
(t/is (= :invalid-image (:code data)))))
(finally
(fs/delete path))))))

View File

@ -70,6 +70,9 @@
(= (:code error) :media-type-mismatch)
(tr "errors.media-type-mismatch")
(= (:code error) :invalid-image)
(tr "errors.media-type-not-allowed")
:else
(tr "errors.unexpected-error"))]
(rx/of (ntf/error msg))))