From 781ca777946f2bbd7f2ca00185033b3d6bd0f1b9 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 19 Jul 2017 22:37:29 +0100 Subject: [PATCH] Do not try to send msg after http request error handled Fixes #1344 --- nodes/core/io/21-httprequest.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/nodes/core/io/21-httprequest.js b/nodes/core/io/21-httprequest.js index 24e7eea18..f7e873c99 100644 --- a/nodes/core/io/21-httprequest.js +++ b/nodes/core/io/21-httprequest.js @@ -244,19 +244,25 @@ module.exports = function(RED) { } } - // Convert the payload to the required return type - msg.payload = Buffer.concat(msg.payload); // bin - if (node.ret !== "bin") { - msg.payload = msg.payload.toString('utf8'); // txt + // Check that msg.payload is an array - if the req error + // handler has been called, it will have been set to a string + // and the error already handled - so no further action should + // be taken. #1344 + if (Array.isArray(msg.payload)) { + // Convert the payload to the required return type + msg.payload = Buffer.concat(msg.payload); // bin + if (node.ret !== "bin") { + msg.payload = msg.payload.toString('utf8'); // txt - if (node.ret === "obj") { - try { msg.payload = JSON.parse(msg.payload); } // obj - catch(e) { node.warn(RED._("httpin.errors.json-error")); } + if (node.ret === "obj") { + try { msg.payload = JSON.parse(msg.payload); } // obj + catch(e) { node.warn(RED._("httpin.errors.json-error")); } + } } - } - node.send(msg); - node.status({}); + node.send(msg); + node.status({}); + } }); }); req.setTimeout(node.reqTimeout, function() {