Skip to content

Commit e09bd18

Browse files
authored
Merge pull request #365 from contentstack/enhancement/DX-2970
enh: modify retry logic based on ratelimit remaining header
2 parents bf0f6ba + 3472b2f commit e09bd18

File tree

5 files changed

+96
-74
lines changed

5 files changed

+96
-74
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## [v1.21.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.4) (2025-06-02)
3+
- Enhancement
4+
- Retry Logic modification on x-ratelimit-remaining Header
5+
26
## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26)
37
- Enhancement
48
- Update addSettings Method to Support Generic Stack Settings Update

lib/core/concurrency-queue.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export function ConcurrencyQueue ({ axios, config }) {
229229
if (!this.config.retryOnError || networkError > this.config.retryLimit) {
230230
return Promise.reject(responseHandler(error))
231231
}
232+
// Check rate limit remaining header before retrying
232233

233234
// Error handling
234235
const wait = this.config.retryDelay
@@ -244,19 +245,26 @@ export function ConcurrencyQueue ({ axios, config }) {
244245
} else {
245246
return Promise.reject(responseHandler(error))
246247
}
247-
} else if ((response.status === 401 && this.config.refreshToken)) {
248-
retryErrorType = `Error with status: ${response.status}`
249-
networkError++
250-
251-
if (networkError > this.config.retryLimit) {
248+
} else {
249+
const rateLimitRemaining = response.headers['x-ratelimit-remaining']
250+
if (rateLimitRemaining !== undefined && parseInt(rateLimitRemaining) <= 0) {
252251
return Promise.reject(responseHandler(error))
253252
}
254-
this.running.shift()
255-
// Cool down the running requests
256-
delay(wait, response.status === 401)
257-
error.config.retryCount = networkError
258-
// deepcode ignore Ssrf: URL is dynamic
259-
return axios(updateRequestConfig(error, retryErrorType, wait))
253+
254+
if ((response.status === 401 && this.config.refreshToken)) {
255+
retryErrorType = `Error with status: ${response.status}`
256+
networkError++
257+
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))
267+
}
260268
}
261269
if (this.config.retryCondition && this.config.retryCondition(error)) {
262270
retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}`

package-lock.json

Lines changed: 2 additions & 62 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.3",
3+
"version": "1.21.4",
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",

0 commit comments

Comments
 (0)