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

Handle 204 in httprequest JSON

If the http statusCode is 204 (Success, No Content) and the node return type is set to JSON this sets msg.payload as an empty json object so as to supress the JSON parse error
This commit is contained in:
Sam Machin 2023-08-02 14:15:29 +01:00 committed by GitHub
parent 877aa75e4e
commit 2b01a3fcd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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