mirror of
https://github.com/penpot/penpot.git
synced 2026-07-22 05:57:56 +00:00
🐛 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:
parent
fc6b3ee7f0
commit
26c4ec18fe
@ -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)))
|
||||
|
||||
@ -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))))))
|
||||
|
||||
|
||||
@ -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))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user