Answer a non-JSON body to the approvals API with 400, not 500 - #712
Merged
davidmckayv merged 3 commits intoOct 2, 2026
Merged
Conversation
The approvals routes' onError mapped only the approval and Zod errors, so the SyntaxError from req.json() answered 500 with the parser's message. Map it to 400 as the delivery routes do.
Chebaleomkar
requested review from
MikeRyanDev,
davidmckayv,
guidovizoso,
mxmzb and
tylerslaton
as code owners
October 2, 2026 19:12
# Conflicts: # CHANGELOG.md
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.
What this changes
The approvals routes'
onError(server/src/approvals/routes.ts) mappedApprovalNotFoundErrorto 404, andApprovalRefusedErrorandZodErrorto 400. TheSyntaxErrorthatcontext.req.json()throws on a body that is not JSON fell through to 500 and echoed the parser's message:PATCH /preferenceswith{oopsanswered500 {"error":"JSON Parse error: Expected '}'"}.It now answers
400 {"error":"Supply a valid request."}, the same answerdelivery/routes.tsgives.Where it runs
Server: every approvals route that reads a JSON body.
Boundary and audit
None.
Changelog
Entry under Unreleased.
Proof
New test in
server/tests/approvals.test.ts. It fails onmain(received 500) and the file passes 17/17 with the fix. Servertscand Biome format and lint are clean.