Improve the Error Messages

pull/1/head
Peter 'Pita' Martischka 2011-04-06 22:53:07 +01:00
parent 5dc72234ab
commit 2d0dc5aab6
1 changed files with 21 additions and 3 deletions

View File

@ -122,21 +122,39 @@ messageHandler.setSocketIO(io);
io.on('connection', function(client){ io.on('connection', function(client){
try{ try{
messageHandler.handleConnect(client); messageHandler.handleConnect(client);
}catch(e){console.error(e);} }catch(e){errorlog(e);}
client.on('message', function(message){ client.on('message', function(message){
try{ try{
messageHandler.handleMessage(client, message); messageHandler.handleMessage(client, message);
}catch(e){console.error(e);} }catch(e){errorlog(e);}
}); });
client.on('disconnect', function(){ client.on('disconnect', function(){
try{ try{
messageHandler.handleDisconnect(client); messageHandler.handleDisconnect(client);
}catch(e){console.error(e);} }catch(e){errorlog(e);}
}); });
}); });
function errorlog(e)
{
var timeStr = new Date().toUTCString() + ": ";
if(typeof e == "string")
{
console.error(timeStr + e);
}
else if(e.stack != null)
{
console.error(timeStr + e.stack);
}
else
{
console.error(timeStr + JSON.stringify(e));
}
}