Handle json parse errors?
See original GitHub issueWhen opt.json
is truthy, errors on JSON.parse()
are swallowed.
https://github.com/Raynos/xhr/blob/bc9674d7d5f5c8870ab23fb736fbacc2b3f73518/index.js#L38-L40
Is there a recommended way of handling these errors while still supporting json: String
option?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Proper way to catch exception from JSON.parse - Stack Overflow
i post something into an iframe then read back the contents of the iframe with json parse...so sometimes it's not a json string....
Read more >How to handle invalid JSON parse error properly.
The most common way to handle JSON parse error is using try-catch block. If the JSON string is valid, it will return a...
Read more >SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >Proper way to catch exception from JSON.parse - Tutorialspoint
The best way to catch invalid JSON parsing errors is to put the calls to JSON.parse() to a try/catch block.
Read more >How to handle errors during Json parse? - Microsoft Q&A
How to handle errors during Json parse? · Dim jsonResponse As JsonNode · Using http As HttpClient = New HttpClient · Dim url...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve just been tripped up by this for a while. If I set json:true then I expect JSON to be returned, not a string. But due to a JSON parsing issue I ended up trying to iterate over the invalid JSON string causing headaches instead.
We should get an error stating that parsing the JSON failed. As it currently stands, we have to manually parse the JSON ourselves or check the type of response.body just to safeguard against it.
I know. That’s a behavior that was there long time ago and it’s a total breaking change, so requires a major release.