kwhitley / itty-router

A little router.
MIT License
1.69k stars 77 forks source link

fix: 216 withContent returning 500 #217

Closed smcstewart closed 3 months ago

smcstewart commented 5 months ago

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

kwhitley commented 3 months ago

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