Skip to content

fix(api): gracefully handle express body-parser 4xx client errors#100

Merged
shenald-dev merged 1 commit intomasterfrom
fix-express-body-parser-errors-7638144141725921686
Apr 29, 2026
Merged

fix(api): gracefully handle express body-parser 4xx client errors#100
shenald-dev merged 1 commit intomasterfrom
fix-express-body-parser-errors-7638144141725921686

Conversation

@shenald-dev
Copy link
Copy Markdown
Owner

Modified src/index.js global error handler to handle specific body-parser errors such as charset.unsupported, encoding.unsupported, and request.aborted correctly instead of throwing 500 Server Errors. Also added tests to tests/api_robustness.test.js to assert the proper 415 and 400 statuses are returned when tested directly using a mocked express app. Updated .jules/bolt.md with learnings from the fix.


PR created automatically by Jules for task 7638144141725921686 started by @shenald-dev

When `express.json()` processes requests with unsupported character sets, unsupported encodings, or aborted connections, it throws specific error types (`charset.unsupported`, `encoding.unsupported`, `request.aborted`). If unhandled, these fall through to the global generic error handler, which throws a 500 Internal Server Error and logs to the console, leading to potential log spam (DoS vector) and incorrect HTTP response codes.

This patch:
- Explicitly catches `charset.unsupported` and `encoding.unsupported` to return a 415 Unsupported Media Type.
- Explicitly catches `request.aborted` to return a 400 Bad Request.
- Adds comprehensive unit tests for these scenarios.
- Avoids repetitive `Buffer` allocations by precomputing standard JSON responses for `415` and `400` errors.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@shenald-dev shenald-dev added bug Something isn't working documentation Improvements or additions to documentation labels Apr 29, 2026
@shenald-dev
Copy link
Copy Markdown
Owner Author

Looks good, merging this in. CI is green and everything checks out 👍

Adds graceful handling of express body-parser 4xx errors and corresponding tests.

@shenald-dev shenald-dev merged commit 58e5499 into master Apr 29, 2026
2 checks passed
@google-labs-jules
Copy link
Copy Markdown
Contributor

Looks good, merging this in. CI is green and everything checks out 👍

Adds graceful handling of express body-parser 4xx errors and corresponding tests.

Acknowledged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant