I am using expressjs' body-parser to parse the body of a request into json, but when I pass invalid json the body-parser middleware sends an error message with more information than necessary.
Here's how I use body parser:
// Use bodyParser to read data from body of Http requests
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
Here's an example of the information passed back when I post with invalid json:
Error: invalid json
<br> at parse (/Users/.../node_modules/body-parser/lib/types/json.js:72:15)
<br> at /Users/.../node_modules/body-parser/lib/read.js:98:18
<br> at IncomingMessage.onEnd (/Users/.../node_modules/body-parser/node_modules/raw-body/index.js:136:7)
<br> at IncomingMessage.g (events.js:180:16)
<br> at IncomingMessage.emit (events.js:92:17)
<br> at _stream_readable.js:943:16
<br> at process._tickCallback (node.js:419:13)
Is there an option I can use to avoid these kinds of responses? I checked the documentation but didn't find anything useful.
Aucun commentaire:
Enregistrer un commentaire