fix: 216 withContent returning 500 #217
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix to return a
400
instead of a500
when using thewithContent
middleware and sending no content or invalid JSON in the request body.Description
Wrapped the
withContent
middleware with atry... catch
to capture any JSON parsing issues and return them as400 Bad Request
instead of500 Internal Server Error
. Added tests to check for the error, and that the router returns a400
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
withContent
middleware, this may cause an issue. Otherwise, this captures the invalid JSON input and returns a "more correct" HTTP status code.