how to detect invalid JSON and response some helpful message?
See original GitHub issuesome guy may try to post some wired string and set header to be json, i can caught the error but don’t know how to response a custom message that tell them," dude, your json is invalid !"
i tried something like this:
app.use(function*(next){
if(/get|delete|head/i.test(this.method)) return yield next;
if( /json/i.test( this.get('Content-Type') ) ){
try{
require('co-body').json(this)()....... blah blah blah.....
}catch(e){
}
}
yield bodyParser({
formLimit: '200kb',
jsonLimit: '1mb',
}).call(this,next)
});
i looked the source code, there is no error handling;
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
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 >How to Fix the Invalid JSON Response Error in WordPress
Learn what's causing the invalid JSON response error on your WordPress site as well as the different ways you can fix it.
Read more >1. Warning: Invalid JSON response - DataTables
A warning from DataTables stating "Invalid JSON response" is one of the most common errors that can occur with DataTables. Fortunately it is...
Read more >JSON Online Validator and Formatter - JSON Lint
Using JSONLint, you can quickly find any errors that might've occurred, allowing youto focus more on the rest of your code than on...
Read more >Invalid JSON message received - Stack Overflow
You can use a site like JSONLint to inspect whether or not the JSON you're trying to send is properly formatted.
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
https://github.com/koajs/bodyparser/commit/194181298fe3bffce6b5fcf3cfebc35b8cda6c89
pretty efficient!