useid / handlersjs

MIT License
3 stars 3 forks source link

Sending incorrect JSON body still results in 500 internal server error #205

Closed AbelVandenBriel closed 2 years ago

AbelVandenBriel commented 2 years ago

When testing magic links on a local instance of the proxy:

image

Accidentally included a comment, which obviously is not possible in JSON. However, the resulting response should be a 400 telling me my JSON was wrong, not a 500 internal server error making me think the issue is with the proxy itself:

image

┆Issue is synchronized with this Wrike task by Unito

AbelVandenBriel commented 2 years ago

Note: this seems to be a handlersjs issue, not a proxy issue

Edit: Transferred the issue to handlersjs after discovering this.

AbelVandenBriel commented 2 years ago

In the NodeHttpRequestResponseHandler, a call is made to parseBody in the handle function in large pipe, which will simply attempt to parse the body as JSON. If this fails, an error is thrown and caught in the catchError rxjs function. image

There, we are simply returning an Internal Server Error - ALWAYS. This makes sense in some cases, as crashing in this handler likely means something went wrong internally, but in this case it's just that the JSON body that was claimed to be valid json in the content-type header simply wasn't valid, and we should let the sender know that in a valid error response.