Skip to content

Commit 3c883b7

Browse files
Merge pull request #37 from dadi/fix/error-handle
Check for headers object within error response
2 parents 11deb53 + a755758 commit 3c883b7

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

lib/helpers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ module.exports = function (APIWrapper) {
4444

4545
return authenticatedRequest(options).catch(err => {
4646
// Check for an expired token and request a new one
47-
if (err.response && err.response.headers['www-authenticate'].indexOf('invalid_token') !== -1) {
47+
if (err.response &&
48+
err.response.headers &&
49+
typeof err.response.headers['www-authenticate'] === 'string' &&
50+
err.response.headers['www-authenticate'].indexOf('invalid_token') !== -1) {
4851
this._log(`The request failed due to an invalid bearer token. Requesting a new one...`)
4952

5053
return passport.refreshToken().then(token => {
5154
return this._processRequest(this.originalRequestObject)
5255
})
5356
}
57+
58+
return Promise.reject(err)
5459
})
5560
})
5661
}

test/unit/terminators.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ describe('Terminators', function (done) {
164164

165165
// Set up the http intercepts - we ask it to return the same document we passed in
166166
// because that's what'll happen anyway
167+
delete documents[0]._id
168+
delete documents[1]._id
167169
var postScope = nock(host).post(post, documents).reply(200, { results: [ fakeResponse.results ] })
168-
169170
return wrapper
170171
.useVersion('1.0')
171172
.useDatabase('test')

0 commit comments

Comments
 (0)