Skip to content

Commit 25f8f76

Browse files
authored
Merge pull request #87 from contentstack/fix/CS-41164-Refresh-Token-Error-Message
fix: 🐛 error message fix on refresh token error
2 parents 3aaa883 + cbc443a commit 25f8f76

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

lib/core/concurrency-queue.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ export function ConcurrencyQueue ({ axios, config }) {
147147
axios.httpClientParams.headers.authtoken = token.authtoken
148148
this.config.authtoken = token.authtoken
149149
}
150-
}).catch(() => {
150+
}).catch((error) => {
151151
this.queue.forEach(queueItem => {
152152
queueItem.reject({
153153
errorCode: '401',
154-
errorMessage: 'Unable to refresh token',
154+
errorMessage: (error instanceof Error) ? error.message : error,
155155
code: 'Unauthorized',
156-
message: 'Request failed with status code 401',
156+
message: 'Unable to refresh token',
157157
name: 'Token Error',
158158
config: queueItem.request
159159
})

lib/stack/roles/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import cloneDeep from 'lodash/cloneDeep'
22
import { create, update, deleteEntity, fetch, query, fetchAll } from '../../entity'
3-
import ContentstackCollection from '../../contentstackCollection'
4-
import error from '../../core/contentstackError'
53
/**
64
* 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>.
75
* @namespace Role

test/unit/concurrency-Queue-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ describe('Concurrency queue test', () => {
163163
.catch(done)
164164
})
165165

166+
it('should give passed error message when refreshToken function fails', done => {
167+
const axios = client({
168+
baseURL: `${host}:${port}`,
169+
authorization: 'Bearer <token_value>',
170+
logHandler: logHandlerStub,
171+
refreshToken: () => {
172+
return new Promise((resolve, reject) => {
173+
reject(new Error('Rejected in Promise'))
174+
})
175+
}
176+
})
177+
Promise.all(sequence(3).map(() => axios.axiosInstance.get('/unauthorized')))
178+
.catch(err => {
179+
expect(err.errorCode).to.equal('401')
180+
expect(err.errorMessage).to.equal('Rejected in Promise')
181+
expect(err.message).to.equal('Unable to refresh token')
182+
done()
183+
})
184+
})
185+
166186
it('Initialize with bad axios instance', done => {
167187
try {
168188
new ConcurrencyQueue({ axios: undefined })

0 commit comments

Comments
 (0)