diff --git a/server.js b/server.js index 25e095d..56b0483 100644 --- a/server.js +++ b/server.js @@ -141,12 +141,16 @@ Server.prototype.on_tcp_connection = function(connection) { } if(length !== null && bytes_received == 2 + length) { - // All of the data (plus the 2-byte length prefix) is received. - var data = Buffer.concat(bufs) - , req = new Request(data, connection) - , res = new Response(data, connection) - - self.emit('request', req, res) + try { + // All of the data (plus the 2-byte length prefix) is received. + var data = Buffer.concat(bufs) + , req = new Request(data, connection) + , res = new Response(data, connection) + + self.emit('request', req, res) + } catch (err) { + self.emit('error', err); + } } }) } @@ -164,10 +168,14 @@ Server.prototype.on_udp = function(data, rinfo) { , 'end' : function() {} } - var req = new Request(data, connection) - , res = new Response(data, connection) + try { + var req = new Request(data, connection) + , res = new Response(data, connection) - self.emit('request', req, res) + self.emit('request', req, res) + } catch (err) { + self.emit('error', err); + } }