Difficult to determine that an error is the result of bad JSON
See original GitHub issueHaving SyntaxErrors
consistently returned (#119) and a status code provided means we can fairly reliably detect errors in express middleware that are the result of bad JSON.
app.use(function(err, req, res, next) {
if (err instanceof SyntaxError && err.status === 400) {
console.error('Bad JSON');
}
});
This test could theoretically give false positives though, if some other middleware were to throw something similar. Imagine we’re using body-parser
first and then something else to validate the body has the structure we’re expecting, for example.
Is there any way to detect JSON parsing error with 100% reliability with the library as it is now? Is there something you could (perhaps in 2.0) to make this a little easier?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:6
- Comments:26 (9 by maintainers)
Top Results From Across the Web
Most efficient way to fix an invalid JSON - Stack Overflow
It needs to be converted to valid JSON first. ... var a = new JavaScriptSerializer(); Dictionary<string, object> results = a.
Read more >How to Fix the Invalid JSON Response Error in WordPress
Check your WordPress site URL. ... Another common cause of the invalid JSON response error is a problem with your WordPress site URLs....
Read more >How to Fix the Invalid JSON Error in WordPress? - Rank Math
In this article, learn how to fix the invalid JSON error - 'Updating failed. The response is not a valid JSON response.' with...
Read more >Solved: Find event with invalid JSON - Splunk Community
Trying to find a consistent way of finding events that contain invalid JSON. We've ran into all sorts of different issues with escape...
Read more >SyntaxError: JSON.parse: bad parsing Breaking Your Code ...
Traveling deftly through to the next item in our JavaScript Error Handling series, today we're taking a hard look at the JSON Parse...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
All errors include a
type
property from 1.18.0 release onwards. For parse failure,err.type === 'entity.parse.failed'
.That’s fine, I trust your judgement 😃
I’ll stick with