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

Added error trap to xml2js node.

This commit is contained in:
Dave C-J 2013-10-22 20:25:14 +01:00
parent 612dd4dc7f
commit 3b60e1a0e3
2 changed files with 48 additions and 47 deletions

View File

@ -22,24 +22,25 @@ try {
var eyes = require("eyes"); var eyes = require("eyes");
gotEyes = true; gotEyes = true;
} catch(e) { } catch(e) {
util.log("[73-parsexml.js] Warning: Module 'eyes' not installed"); util.log("[73-parsexml.js] Note: Module 'eyes' not installed. (not needed, but useful)");
} }
function Xml2jsNode(n) { function Xml2jsNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.useEyes = n.useEyes; this.useEyes = n.useEyes;
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
parseString(msg.payload, function (err, result) { parseString(msg.payload, function (err, result) {
if (err) { node.error(err; }
else {
msg.payload = result; msg.payload = result;
node.send(msg); node.send(msg);
if (node.useEyes == true) { if (node.useEyes == true) {
if (gotEyes == true) { eyes.inspect(msg); } if (gotEyes == true) { eyes.inspect(msg); }
else { node.log(JSON.stringify(msg)); } else { node.log(JSON.stringify(msg)); }
} }
}
}); });
}); });
} }
RED.nodes.registerType("xml2js",Xml2jsNode); RED.nodes.registerType("xml2js",Xml2jsNode);