1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #4262 from sammachin/patch-3

Handle 204 in httprequest JSON
This commit is contained in:
Nick O'Leary 2023-08-14 11:10:24 +01:00 committed by GitHub
commit 97470e94f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -637,6 +637,7 @@ in your Node-RED user directory (${RED.settings.userDir}).
msg.payload = msg.payload.toString('utf8'); // txt msg.payload = msg.payload.toString('utf8'); // txt
if (node.ret === "obj") { if (node.ret === "obj") {
if (msg.statusCode == 204){msg.payload= "{}"};
try { msg.payload = JSON.parse(msg.payload); } // obj try { msg.payload = JSON.parse(msg.payload); } // obj
catch(e) { node.warn(RED._("httpin.errors.json-error")); } catch(e) { node.warn(RED._("httpin.errors.json-error")); }
} }

View File

@ -667,7 +667,7 @@ describe('HTTP Request Node', function() {
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property('payload',''); msg.should.have.property('payload',{});
msg.should.have.property('statusCode',204); msg.should.have.property('statusCode',204);
done(); done();
} catch(err) { } catch(err) {