Skip to content

Commit

Permalink
Merge pull request #88 from avital/wrap-errors-in-connection
Browse files Browse the repository at this point in the history
In client, wrap errors in Error object so they pass through event emi…
  • Loading branch information
avital committed Jun 3, 2016
2 parents 4bf6fa6 + d868fd2 commit 9b85288
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/client/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ Connection.prototype.bindToSocket = function(socket) {
* @param {String} message.a action
*/
Connection.prototype.handleMessage = function(message) {
var err = message.error;
if (err) {
var err = null;
if (message.error) {
// wrap in Error object so can be passed through event emitters
err = new Error;
for (var key in message.error) {
err[key] = message.error[key];
}

// Add the message data to the error object for more context
err.data = message;
delete message.error;
Expand Down

0 comments on commit 9b85288

Please sign in to comment.