http-in not handling post error if headers set to application/json and non-json received
See original GitHub issueIf an http-in is set to accept POST input - and the sender sets the header to application/json - but then sends a payload that is NOT json… the error is not surfaced via the catch node…
Error: invalid json at parse (/Users/*****/node-red/node_modules/express/node_modules/connect/node_modules/body-parser/lib/types/json.js:64:15) at /Users/****/node-red/node_modules/express/node_modules/connect/node_modules/body-parser/lib/read.js:91:18 at IncomingMessage.onEnd (/Users/****/node-red/node_modules/express/node_modules/connect/node_modules/body-parser/node_modules/raw-body/index.js:136:7) at IncomingMessage.g (events.js:180:16) at IncomingMessage.emit (events.js:92:17) at _stream_readable.js:944:16 at process._tickCallback (node.js:442:13)
simple flow to demo this is
[{"id":"3ca4b708.c35b48","type":"http in","name":"","url":"/dummy","method":"post","swaggerDoc":"","x":170.88888549804688,"y":668.5555579044202,"z":"f307b843.0cf848","wires":[["a4b95451.5b46a8"]]},{"id":"12a3e242.ed5c1e","type":"catch","name":"","x":195.88888549804688,"y":712.5555579044202,"z":"f307b843.0cf848","wires":[["629ea4db.9d615c"]]},{"id":"a4b95451.5b46a8","type":"debug","name":"","active":true,"console":"true","complete":"true","x":402.8888854980469,"y":669.5555725097656,"z":"f307b843.0cf848","wires":[]},{"id":"629ea4db.9d615c","type":"debug","name":"","active":true,"console":"false","complete":"true","x":420.8888854980469,"y":713.5555725097656,"z":"f307b843.0cf848","wires":[]},{"id":"c135fd63.3eca","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":93.88888549804688,"y":618.5555725097656,"z":"f307b843.0cf848","wires":[["1e8f148d.e170eb"]]},{"id":"9de7fa99.621808","type":"debug","name":"","active":true,"console":"false","complete":"true","x":575.888916015625,"y":616.5555267333984,"z":"f307b843.0cf848","wires":[]},{"id":"386967b0.c79698","type":"http request","name":"","method":"POST","ret":"txt","url":"localhost:1880/red/dummy","x":408.8888854980469,"y":616.5555267333984,"z":"f307b843.0cf848","wires":[["9de7fa99.621808"]]},{"id":"1e8f148d.e170eb","type":"function","name":"add header","func":"msg.headers= {\"Content-Type\":\"application/json\"};\nreturn msg;","outputs":1,"noerr":0,"x":245.88888549804688,"y":617.5555267333984,"z":"f307b843.0cf848","wires":[["386967b0.c79698"]]}]
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
Just to confirm, this is still an issue after the move to express 4
Just change function init from file red/api/index.js
from adminApp.use(bodyParser.json({limit:maxApiRequestSize})); to ` this.addRawBody = function (req, res, buf, encoding) { req.rawBody = buf.toString(); }
`