question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to detect invalid JSON and response some helpful message?

See original GitHub issue

some 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:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found