Skip to content

Commit c25ccde

Browse files
Merge pull request #375 from contentstack/staging
DX | 13-06-2025 | Release
2 parents 0b4907d + 937816a commit c25ccde

File tree

5 files changed

+19
-91
lines changed

5 files changed

+19
-91
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
3+
## [v1.21.6](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.6) (2025-06-11)
4+
- Fix
5+
- Revert Retry Logic modification on x-ratelimit-remaining Header
6+
27
## [v1.21.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.5) (2025-06-09)
38
- Enhancement
49
- Preview token support added

lib/core/concurrency-queue.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,19 @@ export function ConcurrencyQueue ({ axios, config }) {
245245
} else {
246246
return Promise.reject(responseHandler(error))
247247
}
248-
} else {
249-
const rateLimitRemaining = response.headers['x-ratelimit-remaining']
250-
if (rateLimitRemaining !== undefined && parseInt(rateLimitRemaining) <= 0) {
251-
return Promise.reject(responseHandler(error))
252-
}
253-
254-
if ((response.status === 401 && this.config.refreshToken)) {
255-
retryErrorType = `Error with status: ${response.status}`
256-
networkError++
248+
} else if ((response.status === 401 && this.config.refreshToken)) {
249+
retryErrorType = `Error with status: ${response.status}`
250+
networkError++
257251

258-
if (networkError > this.config.retryLimit) {
259-
return Promise.reject(responseHandler(error))
260-
}
261-
this.running.shift()
262-
// Cool down the running requests
263-
delay(wait, response.status === 401)
264-
error.config.retryCount = networkError
265-
// deepcode ignore Ssrf: URL is dynamic
266-
return axios(updateRequestConfig(error, retryErrorType, wait))
252+
if (networkError > this.config.retryLimit) {
253+
return Promise.reject(responseHandler(error))
267254
}
255+
this.running.shift()
256+
// Cool down the running requests
257+
delay(wait, response.status === 401)
258+
error.config.retryCount = networkError
259+
// deepcode ignore Ssrf: URL is dynamic
260+
return axios(updateRequestConfig(error, retryErrorType, wait))
268261
}
269262
if (this.config.retryCondition && this.config.retryCondition(error)) {
270263
retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}`

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.21.5",
3+
"version": "1.21.6",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

test/unit/concurrency-Queue-test.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -506,76 +506,6 @@ describe('Concurrency queue test', () => {
506506
})
507507
.catch(done)
508508
})
509-
510-
it('should not retry when rate limit remaining is 0', done => {
511-
const mock = new MockAdapter(api)
512-
mock.onGet('/ratelimit').reply(429, { errorCode: 429 }, {
513-
'x-ratelimit-remaining': '0'
514-
})
515-
516-
reconfigureQueue({
517-
retryOnError: true,
518-
retryLimit: 3,
519-
retryDelay: 300
520-
})
521-
522-
api.get('/ratelimit')
523-
.catch(error => {
524-
expect(error.response.status).to.equal(429)
525-
expect(error.config.retryCount).to.equal(0) // Should not have retried
526-
expect(logHandlerStub.callCount).to.equal(0) // No retry logs
527-
mock.restore()
528-
done()
529-
})
530-
})
531-
532-
it('should retry when rate limit remaining is greater than 0', done => {
533-
const mock = new MockAdapter(api)
534-
mock.onGet('/ratelimit').reply(429, { errorCode: 429 }, {
535-
'x-ratelimit-remaining': '5'
536-
})
537-
mock.onGet('/ratelimit').reply(200, { success: true })
538-
539-
reconfigureQueue({
540-
retryOnError: true,
541-
retryLimit: 3,
542-
retryDelay: 300
543-
})
544-
545-
api.get('/ratelimit')
546-
.then(response => {
547-
/* eslint-disable no-unused-expressions */
548-
expect(response.status).to.equal(200)
549-
expect(response.data.success).to.be.true
550-
/* eslint-enable no-unused-expressions */
551-
mock.restore()
552-
done()
553-
})
554-
.catch(done)
555-
})
556-
557-
it('should retry when rate limit remaining header is not present', done => {
558-
const mock = new MockAdapter(api)
559-
mock.onGet('/ratelimit').reply(429, { errorCode: 429 })
560-
mock.onGet('/ratelimit').reply(200, { success: true })
561-
562-
reconfigureQueue({
563-
retryOnError: true,
564-
retryLimit: 3,
565-
retryDelay: 300
566-
})
567-
568-
api.get('/ratelimit')
569-
.then(response => {
570-
/* eslint-disable no-unused-expressions */
571-
expect(response.status).to.equal(200)
572-
expect(response.data.success).to.be.true
573-
/* eslint-enable no-unused-expressions */
574-
mock.restore()
575-
done()
576-
})
577-
.catch(done)
578-
})
579509
})
580510

581511
function makeConcurrencyQueue (config) {

0 commit comments

Comments
 (0)