Quantcast
Channel: How can I catch errors in a JSON post in express.js - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How can I catch errors in a JSON post in express.js

$
0
0

I am creating an API in express.js where by the user posts JSON.

I've set the content type to application/json in the clients request. If I post valid JSON, all is well. However, posintg malformed JSON results in express throwing the following error...

string(370) "SyntaxError: Unexpected token } at Object.parse (native) at IncomingMessage. (/var/www/vhost/rest-v1/node/node_modules/express/node_modules/connect/lib/middleware/json.js:76:27) at IncomingMessage.EventEmitter.emit (events.js:92:17) at _stream_readable.js:910:16 at process._tickCallback (node.js:415:13)"

How can I catch this error so that I can respond with a more meaningful error message to the user?


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>