diff --git a/src/thrift/thrift.js b/src/thrift/thrift.js index f0964d5..9f9f664 100644 --- a/src/thrift/thrift.js +++ b/src/thrift/thrift.js @@ -182,7 +182,16 @@ Thrift.Method.prototype.processResponse = function (response, callback) { callback = callback || Thrift.Method.noop; - var header = response.readMessageBegin(); + try { + header = response.readMessageBegin(); + } + catch (exception) { + err = Error('Failed to readMessageBegin. Received [' + exception + ']'); + response.readMessageEnd(); + callback(err); + return; + } + if (header.mtype == Thrift.MessageType.EXCEPTION) { err = Thrift.TApplicationException.read(response); response.readMessageEnd(); @@ -202,7 +211,15 @@ Thrift.Method.prototype.processResponse = function (response, callback) { return; } - result = this.result.read(response); + try { + result = this.result.read(response); + } + catch (exception) { + err = Error('Failed to read from response. Received [' + exception + ']'); + response.readMessageEnd(); + callback(err); + return; + } response.readMessageEnd(); // Exceptions are in fields