Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 error message fix on refresh token error #87

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading