nayrnet / node-hikvision-api

NodeJS Module for Hikvision IPC HTTP API
GNU General Public License v3.0
193 stars 66 forks source link

Gracefully handle connect errors #3

Open ghost opened 8 years ago

ghost commented 8 years ago

I'm using the api as per the example but I'm running 5 instances.

var hikvision1 = new ipcamera.hikvision(options1);
var hikvision2 = new ipcamera.hikvision(options2);
etc ...

It works well but this morning one of my cameras stopped responding. It caused my javascript to exit with the following error:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: connect EHOSTUNREACH 192.168.2.24:80
    at Object.exports._errnoException (util.js:907:11)
    at exports._exceptionWithHostPort (util.js:930:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)

It resulted in that monitoring of all my 5 cameras ceased working. Can the code be altered in some way to gracefully handle a connection error without crashing my javascript?