Skip to content

fix: Max retry count reached error #1943

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 30, 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
32 changes: 16 additions & 16 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 packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@oclif/plugin-help": "^6.2.27",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"@oclif/plugin-plugins": "^5.4.36",
"chalk": "^4.1.2",
"fast-csv": "^4.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@contentstack/cli-cm-seed": "~1.11.1",
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"inquirer": "8.2.6",
"mkdirp": "^1.0.4",
"tar": "^6.2.1 "
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@oclif/core": "^4.2.7",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"chalk": "^4.1.2",
"just-diff": "^6.0.2",
"lodash": "^4.17.21"
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"chalk": "^4.1.2",
"dotenv": "^16.4.7",
"inquirer": "8.2.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@contentstack/cli-cm-export": "~1.16.2",
"@contentstack/cli-cm-import": "~1.22.1",
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"chalk": "^4.1.2",
"inquirer": "8.2.6",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"format": "eslint src/**/*.ts --fix"
},
"dependencies": {
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"contentstack": "^3.25.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"fast-csv": "^4.3.6",
"inquirer": "8.2.6",
"inquirer-checkbox-plus-prompt": "1.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-variants": "~1.2.1",
"@oclif/core": "^4.2.7",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"async": "^3.2.6",
"big-json": "^3.2.0",
"bluebird": "^3.7.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import-setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@oclif/core": "^4.2.7",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"big-json": "^3.2.0",
"chalk": "^4.1.2",
"fs-extra": "^11.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@contentstack/cli-audit": "~1.12.1",
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"@contentstack/management": "~1.20.2",
"@contentstack/cli-variants": "~1.2.1",
"@oclif/core": "^4.2.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-migrate-rte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"@contentstack/json-rte-serializer": "~2.0.11",
"collapse-whitespace": "^1.1.7",
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"async": "^3.2.6",
"callsites": "^3.1.0",
"cardinal": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@contentstack/cli-cm-import": "~1.22.1",
"@contentstack/cli-command": "~1.5.0",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"@contentstack/management": "~1.20.2",
"inquirer": "8.2.6",
"mkdirp": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-utilities/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-utilities",
"version": "1.11.1",
"version": "1.11.2",
"description": "Utilities for contentstack projects",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
31 changes: 16 additions & 15 deletions packages/contentstack-utilities/src/authentication-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ class AuthenticationHandler {

async refreshAccessToken(error: any, maxRetryCount = 1): Promise<void> {
if (error.response && error.response.status) {
console.error(error.response);
if (maxRetryCount >= 3) {
ux.print('Max retry count reached, please login to proceed', {
color: 'yellow',
});
process.exit(1);
}

maxRetryCount++; // Increment for the next retry attempt

switch (error.response.status) {
case 401:
// NOTE: Refresh the token if the type is OAuth.
Expand All @@ -74,12 +64,25 @@ class AuthenticationHandler {
if (u.host) hostName = u.host;
}
hostName = hostName || region.cma;
await this.refreshToken(hostName);
return this.refreshAccessToken(error, maxRetryCount); // Retry after refreshing the token
const refreshed = await this.refreshToken(hostName);
if (refreshed) {
return this.refreshAccessToken(error, maxRetryCount); // Retry after refreshing the token
}
console.log('API(401) case error:-', error.response);
// For Basic Auth, exit immediately without retrying
return;
}
break;

case 429:
case 408:
if (maxRetryCount >= 3) {
ux.print('Max retry count reached, please login to proceed', {
color: 'yellow',
});
process.exit(1);
}
maxRetryCount++; // Increment for the next retry attempt
// These cases require a wait, adding a delay before retrying
await new Promise((resolve) => setTimeout(resolve, 1000)); // wait for 1 second
return this.refreshAccessToken(error, maxRetryCount); // Retry
Expand All @@ -93,8 +96,6 @@ class AuthenticationHandler {
refreshToken(hostName: string): Promise<boolean> {
return new Promise<boolean>((resolve) => {
if (this.authType === 'BASIC') {
// NOTE Handle basic auth 401 here
resolve(false);
ux.print('Session timed out, please login to proceed', {
color: 'yellow',
});
Expand All @@ -109,10 +110,10 @@ class AuthenticationHandler {
resolve(true);
})
.catch((error: any) => {
console.log(error);
resolve(false);
});
} else {
resolve(false);
ux.print('You do not have the permissions to perform this action, please login to proceed', {
color: 'yellow',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3776,7 +3776,7 @@ USAGE
$ csdx launch:functions [-p <value>] [-d <value>]

FLAGS
-d, --data-dir=<value> [default: /Users/aman.kumar/Documents/cli-repos/cli/packages/contentstack] Current working
-d, --data-dir=<value> [default: /Users/aman.kumar/Documents/datasync-repo/cli/packages/contentstack] Current working
directory
-p, --port=<value> [default: 3000] Port number

Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@contentstack/cli-config": "~1.12.1",
"@contentstack/cli-launch": "^1.8.0",
"@contentstack/cli-migration": "~1.7.2",
"@contentstack/cli-utilities": "~1.11.1",
"@contentstack/cli-utilities": "~1.11.2",
"@contentstack/cli-variants": "~1.2.1",
"@contentstack/management": "~1.20.3",
"@oclif/core": "^4.2.10",
Expand Down
Loading
Loading