Skip to content

fix: return 400 instead of 500 for malformed JSON body in POST /api/bounties - #512

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
0xzino:fix/malformed-json-400
Jul 31, 2026
Merged

fix: return 400 instead of 500 for malformed JSON body in POST /api/bounties#512
ralyodio merged 1 commit into
profullstack:masterfrom
0xzino:fix/malformed-json-400

Conversation

@0xzino

@0xzino 0xzino commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

POST /api/bounties returns HTTP 500 for malformed JSON because request.json() throws inside the broad error handler.

Fix

Added inner try/catch around request.json() that returns HTTP 400 before reaching schema validation or the database.

Changes

  • route.ts: Catch JSON parse errors explicitly
  • route.test.ts: Added regression test

Test

✓ POST /api/bounties > returns 400 for malformed JSON body and never calls Supabase

Closes #509

…ounties

Handle JSON parse failures explicitly before schema validation.
Previously, request.json() threw inside the broad error handler which
returned 500. Now returns 400 with 'Malformed JSON body' message.

Closes profullstack#509
@ralyodio
ralyodio merged commit 8c1eed9 into profullstack:master Jul 31, 2026
5 checks passed
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.

POST /api/bounties returns 500 for malformed JSON bodies

2 participants