Merge error and fatal

This commit is contained in:
Michael Morrison 2014-02-02 05:58:36 -06:00
parent e857eb1b47
commit 9ebb95c69d
7 changed files with 17 additions and 20 deletions

View file

@ -12,7 +12,7 @@ module.exports = require('./protocols/core').extend({
uri: 'http://'+this.options.address+':'+this.options.port+'/',
timeout: 3000,
}, function(e,r,body) {
if(e) return self.error('HTTP error');
if(e) return self.fatal('HTTP error');
var m = body.match(/status server for (.*?)\r|\n/);
if(m) state.name = m[1];

View file

@ -12,7 +12,7 @@ module.exports = require('./protocols/core').extend({
uri: 'http://mutantfactions.net/game/receiveLobby.php',
timeout: 3000,
}, function(e,r,body) {
if(e) return self.error('Lobby request error');
if(e) return self.fatal('Lobby request error');
var split = body.split('<br/>');

View file

@ -22,11 +22,8 @@ module.exports = Class.extend(EventEmitter,{
},10000);
},
fatal: function(err) {
this.error(err,true);
},
error: function(err,fatal) {
if(!fatal && this.attempt < this.maxAttempts) {
fatal: function(err,noretry) {
if(!noretry && this.attempt < this.maxAttempts) {
this.attempt++;
this.start();
return;
@ -115,7 +112,7 @@ module.exports = Class.extend(EventEmitter,{
function resolveStandard(host,c) {
dns.lookup(host, function(err,address,family) {
if(err) return self.error(err);
if(err) return self.fatal(err);
self.options.address = address;
c();
});
@ -248,10 +245,10 @@ module.exports = Class.extend(EventEmitter,{
});
if(!ondata) return;
//self.tcpTimeoutTimer = self.setTimeout(function() {
// self.tcpCallback = false;
// self.error('timeout');
//},1000);
self.tcpTimeoutTimer = self.setTimeout(function() {
self.tcpCallback = false;
self.fatal('TCP Watchdog Timeout');
},1000);
self.tcpCallback = ondata;
});
},
@ -269,7 +266,7 @@ module.exports = Class.extend(EventEmitter,{
self.udpCallback = false;
var timeout = false;
if(!ontimeout || ontimeout() !== true) timeout = true;
if(timeout) self.error('timeout');
if(timeout) self.fatal('UDP Watchdog Timeout');
},1000);
self.udpCallback = onpacket;
});

View file

@ -151,7 +151,7 @@ module.exports = require('./core').extend({
var list = [];
for(var i = 0; i < numPackets; i++) {
if(!(i in packets)) {
self.error('Missing packet #'+i);
self.fatal('Missing packet #'+i);
return true;
}
list.push(packets[i]);

View file

@ -34,13 +34,13 @@ module.exports = require('./core').extend({
if(cmd == 'Connect') {
var client = self.gbxclient = gbxremote.createClient(self.options.port,self.options.host, function(err) {
if(err) return self.error('GBX error '+JSON.stringify(err));
if(err) return self.fatal('GBX error '+JSON.stringify(err));
c();
});
client.on('error',function(){});
} else {
self.gbxclient.methodCall(cmd, params, function(err, value) {
if(err) return self.error('XMLRPC error '+JSON.stringify(err));
if(err) return self.fatal('XMLRPC error '+JSON.stringify(err));
results.push(value);
c();
});

View file

@ -240,7 +240,7 @@ module.exports = require('./core').extend({
var list = [];
for(var i = 0; i < numPackets; i++) {
if(!(i in packets)) {
self.error('Missing packet #'+i);
self.fatal('Missing packet #'+i);
return true;
}
list.push(packets[i]);

View file

@ -16,15 +16,15 @@ module.exports = require('./protocols/core').extend({
token: this.options.token
}
}, function(e,r,body) {
if(e) return self.error('HTTP error');
if(e) return self.fatal('HTTP error');
var json;
try {
json = JSON.parse(body);
} catch(e) {
return self.error('Invalid JSON');
return self.fatal('Invalid JSON');
}
if(json.status != 200) return self.error('Invalid status');
if(json.status != 200) return self.fatal('Invalid status');
json.players.forEach(function(one) {
state.players.push({name:one.nickname,team:one.team});