Skip to content

fix(commandboard-api): return 400 for malformed JSON bodies instead of 500#12

Closed
quappefeeder wants to merge 1 commit into
profullstack:masterfrom
quappefeeder:fix/invalid-json-400
Closed

fix(commandboard-api): return 400 for malformed JSON bodies instead of 500#12
quappefeeder wants to merge 1 commit into
profullstack:masterfrom
quappefeeder:fix/invalid-json-400

Conversation

@quappefeeder

Copy link
Copy Markdown
Contributor

Fixes #11

Summary

Malformed JSON on any POST endpoint previously bubbled the SyntaxError from JSON.parse to the top-level handler, which maps every throw to 500. Client input errors now respond 400 { "error": "Invalid JSON body" }.

Changes

  • readJson() catches parse failures and throws a typed InvalidJsonBodyError
  • top-level catch maps InvalidJsonBodyError → 400; all other errors still → 500
  • contract tests: malformed JSON on all four POST endpoints (/api/tasks, /api/plugins/sh1pt/actions/publish, /api/plugins/c0mpute/jobs/dispatch, /api/plugins/c0mpute/quotes) returns 400, plus a control asserting well-formed but schema-invalid bodies still return 422

Testing

npx vitest run src/contract.test.ts
# Test Files  1 passed (1)
#      Tests  15 passed (15)   (10 existing + 5 new)

Applied via the ugig gig ("will pay $1 USD for bugs reported and fixed with a PR") — ugig user liudong-design.

…f 500

Malformed JSON on any POST endpoint previously bubbled a SyntaxError to
the top-level handler, which mapped every throw to 500. Client input
errors now respond 400 { "error": "Invalid JSON body" } via a typed
InvalidJsonBodyError thrown from readJson().

Adds contract tests covering all four POST endpoints plus a control
asserting schema-invalid (but well-formed) bodies still return 422.

Fixes profullstack#11
@ralyodio ralyodio closed this Jun 12, 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.

commandboard-api: malformed JSON body returns 500 instead of 400 on all POST endpoints

2 participants