-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorController.js
35 lines (30 loc) · 1.14 KB
/
errorController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var wifi = require('./wifiController'),
events = require('events'),
eventEmitter = new events.EventEmitter(),
dgram = require('dgram'),
droneControllerFile = require('./droneController');
var errorController = function(socketInstance, droneControllerInstance, wifiController) {
var droneController = droneControllerInstance,
drone = droneControllerInstance.drone,
socket = socketInstance,
handlingError = false;
wifiController.init(socket, eventEmitter);
process.on('uncaughtException', function(err) {
if ((err.errno === 'EADDRNOTAVAIL' || err.errno ==='ENETUNREACH') && !handlingError) {
// droneController.drone._d2cServer.close();
handlingError = true;
console.log('WiFi network changed.');
socket.emit('WiFiDisconnected');
wifiController.connectDroneWifi();
}
else if (!handlingError) {
throw err;
process.exit(1);
}
});
eventEmitter.on('wifiConnected', function() {
handlingError = false;
droneController.resetDrone();
})
};
module.exports = errorController;