Skip to content

Answer a non-JSON body to the approvals API with 400, not 500 - #712

Merged
davidmckayv merged 3 commits into
CopilotKit:mainfrom
Chebaleomkar:fix/approvals-malformed-json
Oct 2, 2026
Merged

davidmckayv merged 3 commits into
CopilotKit:mainfrom
Chebaleomkar:fix/approvals-malformed-json

Conversation

@Chebaleomkar

Copy link
Copy Markdown
Contributor

What this changes

The approvals routes' onError (server/src/approvals/routes.ts) mapped ApprovalNotFoundError to 404, and ApprovalRefusedError and ZodError to 400. The SyntaxError that context.req.json() throws on a body that is not JSON fell through to 500 and echoed the parser's message: PATCH /preferences with {oops answered 500 {"error":"JSON Parse error: Expected '}'"}.

It now answers 400 {"error":"Supply a valid request."}, the same answer delivery/routes.ts gives.

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 on main (received 500) and the file passes 17/17 with the fix. Server tsc and Biome format and lint are clean.

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.
@davidmckayv
davidmckayv merged commit 55677e7 into CopilotKit:main Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants