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

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")); }
}