Permalink
Browse files

Some more error handling

  • Loading branch information...
1 parent fbde76a commit 299caad0ac6b39917967a3a47abfd5767961f69d @felixge committed Oct 7, 2011
Showing with 12 additions and 1 deletion.
  1. +6 −0 server.js
  2. +6 −1 transport/xhr_polling.js
View
@@ -6,6 +6,12 @@ var batch = 0;
var sockets = [];
var io = require('socket.io').listen(port);
+io.server.on('connection', function(socket) {
+ socket.on('error', function(err) {
+ console.error(err);
+ });
+});
+
io.configure(function() {
io.set('log level', 1);
});
@@ -90,7 +90,12 @@ XhrPolling.prototype.poll = function() {
// Event
if (/5$/.test(type)) {
- var message = JSON.parse(response[3]);
+ try{
+ var message = JSON.parse(response[3]);
+ } catch (err) {
+ self.emit(new Error('Could not parse response: ' + JSON.stringify(response)));
+ return;
+ }
self.emit('message', message);
self.poll();
return;

0 comments on commit 299caad

Please sign in to comment.