Commit 941a172
authored
fix(api): return bad request for malformed notify JSON (JhaSourav07#2060)
## Description
Closes JhaSourav07#2057
## Pillar
- [x] π οΈ Other (Bug fix, refactoring, docs)
## What changed
`POST /api/notify` was parsing `await req.json()` inside the same broad
`try/catch` used for database and persistence failures. When the request
body was malformed JSON, the route returned the generic 500 response
even though the request itself was invalid.
This PR moves JSON parsing into a narrow `try/catch` before validation.
Malformed JSON now returns a 400 response with a clear message, while
the existing database/server error path is left unchanged.
I also added a route regression test that verifies malformed JSON
returns 400 and does not attempt a database connection.
This is a GSSoC 2026 API bug fix contribution. Please add the relevant
GSSoC labels if they are missing.
## Visual Preview
N/A β this is API error handling behavior.
## Local checks
```bash
npm run test -- app/api/notify/route.test.ts
npm run format:check
npm run lint
npm run typecheck
npm run test
```
`npm run lint` reports one existing warning outside the touched files;
there are no lint errors.
## Checklist before requesting a review:
- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally.
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors.
- [x] My commit follows the Conventional Commits format.
- [x] I have updated `README.md` if I added a new theme or URL
parameter.
- [x] I have starred the repo.
- [x] I have made sure that I have only one commit to merge in this PR.
- [x] The SVG output matches the CommitPulse quality standard.1 file changed
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| |||
0 commit comments