Skip to content

Commit

Permalink
Merge pull request #87 from contentstack/fix/CS-41164-Refresh-Token-E…
Browse files Browse the repository at this point in the history
…rror-Message

fix: 🐛 error message fix on refresh token error
  • Loading branch information
nadeem-cs authored Oct 11, 2023
2 parents c6daba3 + ea04684 commit c2c80d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ export function ConcurrencyQueue ({ axios, config }) {
axios.httpClientParams.headers.authtoken = token.authtoken
this.config.authtoken = token.authtoken
}
}).catch(() => {
}).catch((error) => {
this.queue.forEach(queueItem => {
queueItem.reject({
errorCode: '401',
errorMessage: 'Unable to refresh token',
errorMessage: (error instanceof Error) ? error.message : error,
code: 'Unauthorized',
message: 'Request failed with status code 401',
message: 'Unable to refresh token',
name: 'Token Error',
config: queueItem.request
})
Expand Down
2 changes: 0 additions & 2 deletions lib/stack/roles/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import cloneDeep from 'lodash/cloneDeep'
import { create, update, deleteEntity, fetch, query, fetchAll } from '../../entity'
import ContentstackCollection from '../../contentstackCollection'
import error from '../../core/contentstackError'
/**
* A role is a collection of permissions that will be applicable to all the users who are assigned this role. Read more about <a href= 'https://www.contentstack.com/docs/guide/users-and-roles#roles'>Roles</a>.
* @namespace Role
Expand Down
20 changes: 20 additions & 0 deletions test/unit/concurrency-Queue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ describe('Concurrency queue test', () => {
.catch(done)
})

it('should give passed error message when refreshToken function fails', done => {
const axios = client({
baseURL: `${host}:${port}`,
authorization: 'Bearer <token_value>',
logHandler: logHandlerStub,
refreshToken: () => {
return new Promise((resolve, reject) => {
reject(new Error('Rejected in Promise'))
})
}
})
Promise.all(sequence(3).map(() => axios.axiosInstance.get('/unauthorized')))
.catch(err => {
expect(err.errorCode).to.equal('401')
expect(err.errorMessage).to.equal('Rejected in Promise')
expect(err.message).to.equal('Unable to refresh token')
done()
})
})

it('Initialize with bad axios instance', done => {
try {
new ConcurrencyQueue({ axios: undefined })
Expand Down

0 comments on commit c2c80d4

Please sign in to comment.