mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Better error catching in ping node for spawn errors...
This commit is contained in:
@@ -18,6 +18,7 @@ module.exports = function(RED) {
|
||||
else { node.error("Sorry - your platform - "+plat+" - is not recognised."); }
|
||||
var res = false;
|
||||
var line = "";
|
||||
var fail = false;
|
||||
//var regex = /from.*time.(.*)ms/;
|
||||
var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/;
|
||||
ex.stdout.on('data', function (data) {
|
||||
@@ -26,7 +27,20 @@ module.exports = function(RED) {
|
||||
//ex.stderr.on('data', function (data) {
|
||||
//console.log('[ping] stderr: ' + data);
|
||||
//});
|
||||
ex.on('error', function (err) {
|
||||
fail = true;
|
||||
if (err.code === "ENOENT") {
|
||||
node.error(err.code + " ping command not found");
|
||||
}
|
||||
else if (err.code === "EACCES") {
|
||||
node.error(err.code + " can't run ping command");
|
||||
}
|
||||
else {
|
||||
node.error(err.code);
|
||||
}
|
||||
});
|
||||
ex.on('close', function (code) {
|
||||
if (fail) { fail = false; return; }
|
||||
var m = regex.exec(line)||"";
|
||||
if (m !== '') {
|
||||
if (m[1]) { res = Number(m[1]); }
|
||||
|
Reference in New Issue
Block a user