Better error message for empty body application/json#1253
Conversation
| if (body === '' || body == null) { | ||
| return done(new FST_ERR_CTP_EMPTY_JSON_BODY(), undefined) | ||
| } | ||
|
|
There was a problem hiding this comment.
@mcollina unfortunately the following block (which you mentioned in previous PR) would give a cryptic parse error like Unexpected token i in JSON at position 2. Maybe we should send a PR to nodejs core? 😄
There was a problem hiding this comment.
It's not a Node core problem, is how JSON.parse is implemented in the JS engine.
The current solution is fine :)
There was a problem hiding this comment.
I like the idea to add this error message. The error is meaningful and doesn't intercept with other error cases. I propose to add it. Something like this makes the difference :)
| }) | ||
| }) | ||
|
|
||
| test(`${upMethod} should fail with empty body and application/json content-type`, t => { |
There was a problem hiding this comment.
Can you add also a test with inject?
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Better error message for case #1251
Another option is to check whether the body is > 2 bytes but I thought this way is more clear.
For custom json parser scenario, I guess it will up to the implementer to handle this?
Checklist
npm run testandnpm run benchmark