Skip to content

Commit

Permalink
Emit catchable error events instead of throwing an exception when mal…
Browse files Browse the repository at this point in the history
…formed frames come in
  • Loading branch information
sorear committed Dec 5, 2012
1 parent bf1ea47 commit 4394f00
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/client.js
Expand Up @@ -78,8 +78,20 @@ function BinaryClient(socket, options) {

data = data.data;


data = util.unpack(data);
try {
data = util.unpack(data);
} catch (ex) {
return self.emit('error', 'Received unparsable message: ' + ex);
}
if (!(data instanceof Array))
return self.emit('error', 'Received non-array message');
if (data.length != 3)
return self.emit('error', 'Received message with wrong part count: ' + data.length);
if ('number' != typeof data[0])
return self.emit('error', 'Received message with non-number type: ' + data[0]);
if ('number' != typeof data[2])
return self.emit('error', 'Received message with non-number streamId: ' + data[2]);

switch(data[0]) {
case 0:
// Reserved
Expand Down

0 comments on commit 4394f00

Please sign in to comment.