diff --git a/lib/core/concurrency-queue.js b/lib/core/concurrency-queue.js
index 21e3fef3..321383af 100644
--- a/lib/core/concurrency-queue.js
+++ b/lib/core/concurrency-queue.js
@@ -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
})
diff --git a/lib/stack/roles/index.js b/lib/stack/roles/index.js
index 31ff38eb..483440ad 100644
--- a/lib/stack/roles/index.js
+++ b/lib/stack/roles/index.js
@@ -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 Roles.
* @namespace Role
diff --git a/test/unit/concurrency-Queue-test.js b/test/unit/concurrency-Queue-test.js
index 8d52fa7e..04a6fb58 100644
--- a/test/unit/concurrency-Queue-test.js
+++ b/test/unit/concurrency-Queue-test.js
@@ -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 ',
+ 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 })