Added error hanler to avoid crahsing node-red.

This commit is contained in:
bladerunner2020
2016-04-01 12:03:58 +03:00
parent a113f4cfb7
commit 667c8be203
2 changed files with 9 additions and 9 deletions

View File

@@ -33,20 +33,20 @@ module.exports = function(RED) {
// action = msg.payload;
action = '';
break;
}
this.on('input', function(msg) {
if (action == '') action = msg.payload;
var connection = new mikrotik(ip, login, pass);
var connection = mikrotik(ip, login, pass, {debug: 0});
connection.on('error', function(err) {
node.error("Connection error: " + err);
});
connection.connect(function(conn) {
var chan = conn.openChannel();
chan.write(action, function() {
chan.on('done',function(data) {
var parsed = mikrotik.parseItems(data);
var pl = [];
@@ -57,8 +57,8 @@ module.exports = function(RED) {
msg.payload = pl;
node.send(msg);
chan.close();
conn.close();
chan.closeOnDone = true;
conn.closeOnDone = true;
});
});

View File

@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-mikrotik",
"version": "0.0.3",
"version": "0.0.4",
"description": "Node to work with Mikrotik WiFi router",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"