Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 216 withContent returning 500 #217

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

smcstewart
Copy link
Contributor

Fix to return a 400 instead of a 500 when using the withContent middleware and sending no content or invalid JSON in the request body.

Description

Wrapped the withContent middleware with a try... catch to capture any JSON parsing issues and return them as 400 Bad Request instead of 500 Internal Server Error. Added tests to check for the error, and that the router returns a 400 when no content or invalid JSON content is sent in the request body.

Related Issue

Link to the related issue: 216: 'withContent' returns a '500' when no body is sent

Type of Change

  • Breaking change (fix that may cause userland code to not work as expected)
    • If anyone relies upon the HTTP status code with the withContent middleware, this may cause an issue. Otherwise, this captures the invalid JSON input and returns a "more correct" HTTP status code.

Fix to return a 400 instead of a 500 when using the `withContent` middleware and sending no content of invalid JSON in the request body.
@kwhitley
Copy link
Owner

Thanks @smcstewart! 500's are bad... this counts as a bug fix in my book :)

@kwhitley kwhitley merged commit 1c4f67b into kwhitley:v4.x Mar 12, 2024
4 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.

2 participants