Skip to content

Better error message for empty body application/json#1253

Merged
mcollina merged 4 commits intonextfrom
appjson-error-next
Nov 21, 2018
Merged

Better error message for empty body application/json#1253
mcollina merged 4 commits intonextfrom
appjson-error-next

Conversation

@cemremengu
Copy link
Copy Markdown
Contributor

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

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

if (body === '' || body == null) {
return done(new FST_ERR_CTP_EMPTY_JSON_BODY(), undefined)
}

Copy link
Copy Markdown
Contributor Author

@cemremengu cemremengu Nov 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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? 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a Node core problem, is how JSON.parse is implemented in the JS engine.
The current solution is fine :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

@delvedor delvedor added the semver-major Issue or PR that should land as semver major label Nov 15, 2018
@delvedor delvedor added this to the v2.0.0 milestone Nov 15, 2018
})
})

test(`${upMethod} should fail with empty body and application/json content-type`, t => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add also a test with inject?

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit 832dae3 into next Nov 21, 2018
@mcollina mcollina deleted the appjson-error-next branch November 21, 2018 08:49
@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

semver-major Issue or PR that should land as semver major

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants