Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError at JSON.parse due to status=204 (no content) #123

Closed
ne-spal opened this issue Apr 16, 2015 · 4 comments
Closed

SyntaxError at JSON.parse due to status=204 (no content) #123

ne-spal opened this issue Apr 16, 2015 · 4 comments

Comments

@ne-spal
Copy link

ne-spal commented Apr 16, 2015

Because of

else if (!body) {
          this._bodyText = ''

and

this.text().then(JSON.parse)
@mislav
Copy link
Contributor

mislav commented Apr 16, 2015

I think this is expected. If you try to parse content with JSON, but the response body isn't valid JSON (such as an empty body) then the exception should be thrown.

@ne-spal
Copy link
Author

ne-spal commented Apr 16, 2015

Yeah, but is it better than just getting "null"?

@mislav
Copy link
Contributor

mislav commented Apr 16, 2015

Yes it's very much better. Because when you're expecting JSON, you won't be expecting null. So it's better to have a descriptive exception that you can handle in exception-handling code, instead of trying to iterate over properties of null and get a more cryptic error.

@ne-spal
Copy link
Author

ne-spal commented Apr 16, 2015

Oh, I got it.
And moreover, it's the same behaviour as the native implementaion.
But I thought it could be an exception for status 204...

@ne-spal ne-spal closed this as completed Apr 16, 2015
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants