Skip to content

fix: return 400 for malformed JSON instead of 500#7

Merged
justin-schroeder merged 1 commit into
standardagents:mainfrom
iRonin:fix/parse-json-body-error
Jun 16, 2026
Merged

fix: return 400 for malformed JSON instead of 500#7
justin-schroeder merged 1 commit into
standardagents:mainfrom
iRonin:fix/parse-json-body-error

Conversation

@iRonin

@iRonin iRonin commented May 23, 2026

Copy link
Copy Markdown
Contributor

Problem

parseJsonBody() in worker/http.ts validates Content-Type but does not wrap request.json(). If the body contains malformed JSON, request.json() throws a raw SyntaxError, which bypasses HttpError handling and renders as a 500 internal_error instead of a 400.

Fix

Wrap request.json() in a try/catch that throws HttpError("Invalid JSON in request body", 400).

Files changed

  • worker/http.ts — try/catch around request.json()
  • worker/index.test.ts — test asserting 400 for malformed JSON

parseJsonBody() did not wrap request.json(), so a SyntaxError from
malformed JSON bubbled up as a 500 internal_error. Now catches the
parse failure and throws a proper HttpError(400).

- worker/http.ts: wrap request.json() in try/catch
- worker/index.test.ts: test verifying 400 response for invalid JSON
@justin-schroeder justin-schroeder merged commit 9d2b916 into standardagents:main Jun 16, 2026
@justin-schroeder

Copy link
Copy Markdown
Contributor

Thanks, @iRonin. I validated this locally, merged it, and I’m including it in the patch release.

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