node.js - bodyParse error suppression -
i'm using bodyparser express accept json requests. whenever pass in incorrectly formed json object returns nasty error via endpoint , logs console well. following error:
syntaxerror: unexpected string @ object.parse (native) @ parse (/users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17) @ /users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/lib/read.js:108:18 @ done (/users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14) @ incomingmessage.onend (/users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7) @ incomingmessage.g (events.js:199:16) @ incomingmessage.emit (events.js:104:17) @ _stream_readable.js:908:16 @ process._tickcallback (node.js:355:11) syntaxerror: unexpected string @ object.parse (native) @ parse (/users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17) @ /users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/lib/read.js:108:18 @ done (/users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14) @ incomingmessage.onend (/users/ddibiase-mbp/documents/projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7) @ incomingmessage.g (events.js:199:16) @ incomingmessage.emit (events.js:104:17) @ _stream_readable.js:908:16 @ process._tickcallback (node.js:355:11)
i'm wondering how can suppress error or patch completely. i've investigated error can't find specific recommendations patching it.
it's common declare error handler express:
app.use(function(err, req, res, next) { ... return res.sendstatus(500); });
this catch errors thrown in middleware body-parser
.
Comments
Post a Comment