Skip to content

Commit

Permalink
Make jwr.error always truthy (even if response data is empty string…
Browse files Browse the repository at this point in the history
… or 0 or `false` or `null`) by always ensuring it is an Error instance.
  • Loading branch information
mikermcneil authored Nov 6, 2016
1 parent c9ec88e commit 8393d87
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion sails.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,24 @@
this.headers = responseCtx.headers || {};
this.statusCode = responseCtx.statusCode || 200;
if (this.statusCode < 200 || this.statusCode >= 400) {
this.error = this.body || this.statusCode;

// Determine the appropriate error message.
var msg;
if (this.statusCode === 0) {
msg = 'Server responded with a '+this.statusCode+' status code';
if (this.body !== undefined && this.body !== null) {
msg += ':\n```\n'+this.body+'\n```';
}
else {
msg += '.';
}
}
else {
msg = 'The socket request failed.';
}

// Now build and attach Error instance.
this.error = new Error(msg);
}
}
JWR.prototype.toString = function() {
Expand Down

0 comments on commit 8393d87

Please sign in to comment.