Skip to content

Commit

Permalink
Throw real errors if a business logic fault occurs.
Browse files Browse the repository at this point in the history
This gives us a stack trace.
  • Loading branch information
DDR0 committed Mar 10, 2017
1 parent 4a9bc9d commit d355513
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,12 @@ module.request = function(context, verb, options, entity, callback) {
res.statusCode >= 300 ||
(_.isObject(body) && body.Fault && body.Fault.Error && body.Fault.Error.length) ||
(_.isString(body) && !_.isEmpty(body) && body.indexOf('<') === 0)) {
callback(err || body, body)
var reportedError = err || body;
if (!(reportedError instanceof Error) && body.Fault && body.Fault.Error && body.Fault.Error.length) {
reportedError = new Error(body.Fault.Error.map(e=>`${e.code} ${e.element?`on ${e.element}: `:''}${e.Message} (${e.Detail})`).join())
reportedError.name = body.Fault.type;
}
callback(reportedError, body)
} else {
callback(null, body)
}
Expand Down

0 comments on commit d355513

Please sign in to comment.