Skip to content

Commit

Permalink
Merge pull request #48 from ncjones/real-error-obj
Browse files Browse the repository at this point in the history
Make rejected promise always yield error instance
  • Loading branch information
AleksandrRogov authored May 3, 2019
2 parents 80cf08a + c5b2e85 commit 3ef9e2a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/requests/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,25 @@ var httpRequest = function (options) {
break;
}
default: // All other statuses are error cases.
var error;
var crmError;
try {
var errorParsed = JSON.parse(rawData);

error = errorParsed.hasOwnProperty('error') && errorParsed.error
crmError = errorParsed.hasOwnProperty('error') && errorParsed.error
? errorParsed.error
: { message: errorParsed.Message };
} catch (e) {
if (rawData.length > 0) {
error = { message: rawData };
crmError = { message: rawData };
}
else {
error = { message: "Unexpected Error" };
crmError = { message: "Unexpected Error" };
}
}
var error = new Error();
Object.keys(crmError).forEach(k => {
error[k] = crmError[k];
})
error.status = res.statusCode;
error.statusText = request.statusText;
errorCallback(error);
Expand Down

0 comments on commit 3ef9e2a

Please sign in to comment.