-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Better error when trying to .json
a Resource
that's not JSON.
#47
Comments
Chrome Bug here: https://code.google.com/p/chromium/issues/detail?id=445041 |
Yeah, that's kinda lame. Thanks for opening the issue on the Chrome side. I was just recently trying
|
Have any specific ideas for how we could improve this? Or should we just wait it out until Chrome makes the first move? |
I think this error is pretty good. "SyntaxError" and "unexpected token" are good clues that's it's invalid JSON. Then you can inspect the response and see it's HTML or other non-JSON data. |
for what it's worth i'm playing with ideas here:- |
It would be nice if there were a better error when trying to
.json
aResource
that's not JSON.Currently in two implementations (this polyfill and Chrome Service Workers) trying to
fetch
and.json()
a non JSON resource throws a not particularly helpful error:-It would make for more less unpleasant debugging / error aggregation if it threw an error along the lines of “Failed to parse {{url}} as JSON”… or something like that…
I know errors aren't spec'd as such so it's not something that should/could be fixed in the spec — but I will raise as an issue in Chrome as well so that GitHub & Chrome's fetches can stay aligned but I think it's something that should be improved and I'm sure you have an idea of what it might look like…
The text was updated successfully, but these errors were encountered: