Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(pool): Reject with an Error instance for HTTP errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed Dec 16, 2016
1 parent 1d1fa41 commit 60c15c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ Pool.prototype.request = function (method, path, data) {
}

if (res.statusCode < 200 || res.statusCode >= 300) {
var error = parsedBody || new Error(body)
var error = new Error()
if (! parsedBody) {
error.message = body
} else {
Object.assign(error, parsedBody)
}
error.statusCode = res.statusCode
return d.reject(error)
}
Expand Down
3 changes: 1 addition & 2 deletions test/local/pool_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ describe('Pool', () => {
.then(function () {
assert(false, 'request should have failed')
}, function (error) {
assert.equal(error instanceof Error, false, 'error is not Error instance')
assert.equal(typeof error, 'object', 'error is object')
assert.equal(error instanceof Error, true, 'error is an Error instance')
assert.equal(Object.keys(error).length, 2, 'error has two properties')
assert.equal(error.statusCode, 418, 'error.statusCode is 418')
assert.equal(error.foo, 'bar', 'other error data is correct')
Expand Down

0 comments on commit 60c15c8

Please sign in to comment.