Skip to content

enh: modify retry logic based on ratelimit remaining header #365

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

Merged
merged 1 commit into from
May 28, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [v1.21.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.4) (2025-06-02)
- Enhancement
- Retry Logic modification on x-ratelimit-remaining Header

## [v1.21.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.3) (2025-05-26)
- Enhancement
- Update addSettings Method to Support Generic Stack Settings Update
Expand Down
30 changes: 19 additions & 11 deletions lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export function ConcurrencyQueue ({ axios, config }) {
if (!this.config.retryOnError || networkError > this.config.retryLimit) {
return Promise.reject(responseHandler(error))
}
// Check rate limit remaining header before retrying

// Error handling
const wait = this.config.retryDelay
Expand All @@ -244,19 +245,26 @@ export function ConcurrencyQueue ({ axios, config }) {
} else {
return Promise.reject(responseHandler(error))
}
} else if ((response.status === 401 && this.config.refreshToken)) {
retryErrorType = `Error with status: ${response.status}`
networkError++

if (networkError > this.config.retryLimit) {
} else {
const rateLimitRemaining = response.headers['x-ratelimit-remaining']
if (rateLimitRemaining !== undefined && parseInt(rateLimitRemaining) <= 0) {
return Promise.reject(responseHandler(error))
}
this.running.shift()
// Cool down the running requests
delay(wait, response.status === 401)
error.config.retryCount = networkError
// deepcode ignore Ssrf: URL is dynamic
return axios(updateRequestConfig(error, retryErrorType, wait))

if ((response.status === 401 && this.config.refreshToken)) {
retryErrorType = `Error with status: ${response.status}`
networkError++

if (networkError > this.config.retryLimit) {
return Promise.reject(responseHandler(error))
}
this.running.shift()
// Cool down the running requests
delay(wait, response.status === 401)
error.config.retryCount = networkError
// deepcode ignore Ssrf: URL is dynamic
return axios(updateRequestConfig(error, retryErrorType, wait))
}
}
if (this.config.retryCondition && this.config.retryCondition(error)) {
retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}`
Expand Down
64 changes: 2 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.21.3",
"version": "1.21.4",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
Loading
Loading