fix: surface informative 415 for rejected image MIME types#2954
fix: surface informative 415 for rejected image MIME types#2954cqnykamp wants to merge 1 commit into
Conversation
The multer fileFilter previously called `cb(null, false)` for unsupported MIME types, which silently dropped the file and caused the handler to emit a generic "Unsupported or missing image" 415. Users had no way to tell whether they hit the type filter or some other failure, and the allowed formats were nowhere in the response. Throw a typed `UnsupportedMimeTypeError` from the filter instead, and extend `handleUploadError` to convert it into a 415 with the allowed list in `details`. The frontend toast already surfaces `err.response.data.details`, so this lands without client changes. Closes Doenet#2940 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
CI status note: 14/15 CI jobs pass. The only failure is This appears to be a pre-existing flake, not a regression from this PR:
I have not pushed any additional changes, since the flake is out of scope for this PR (and I'd be guessing at a frontend race condition I don't have evidence for). Recommendation: either merge despite the known flake, or wait for a future rerun once the flake settles. If brittle1 is consistently broken on |
|
Blocked on #2957 — the failing |
Summary
apps/api/src/media/upload.ts: replace the silentcb(null, false)in the multerfileFilterwith a typedUnsupportedMimeTypeError, and havehandleUploadErrormap it to a 415 carrying the allowed-MIME list indetails.err.response.data.detailsin its toast, so unsupported uploads (SVG, HEIC, PDF, raw, …) now produce a useful "Allowed: image/jpeg, image/png, image/webp, image/gif" message with no client changes.Closes #2940
Test plan
npx vitest run src/media/upload.test.ts— new test coveringhandleUploadErrorfor the unsupported-MIME case passes; remaining failures in the file are pre-existing and only happen whenDATABASE_URLis unset.npx tsc --noEmitclean.🤖 Generated with Claude Code