🐛 Return 400 instead of 500 when ImageMagick fails on invalid images#10643
Open
niwinz wants to merge 1 commit into
Open
🐛 Return 400 instead of 500 when ImageMagick fails on invalid images#10643niwinz wants to merge 1 commit into
niwinz wants to merge 1 commit into
Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: This PR was created with AI assistance
What
When uploading an image that ImageMagick cannot process (e.g., corrupted PNG with invalid IHDR data), the backend returned HTTP 500 with error code
imagemagick-error. The frontend treated this as a server error and displayed the full error page instead of showing a user-friendly notification banner.This PR changes the error to return HTTP 400 with validation error code
invalid-image, so the frontend shows a proper error banner.Why
ImageMagick failures on malformed or oversized images are expected errors caused by user input, not internal server failures. They should be treated as validation errors (HTTP 400) rather than internal errors (HTTP 500).
How
exec-magick!inbackend/src/app/media.cljto raise:type :validation, :code :invalid-imageinstead of:type :internal, :code :imagemagick-error:invalid-imagecase toprocess-errorinfrontend/src/app/main/data/media.cljs(used by profile/team photo uploads)backend/test/backend_tests/media_test.cljto expect:validationtypeCloses #10642