Skip to content

Commit ec9f859

Browse files
authored
Merge pull request #1943 from contentstack/fix/DX-2996-max-retry-error
fix: Max retry count reached error
2 parents d714aaf + 22890c1 commit ec9f859

File tree

20 files changed

+64
-63
lines changed

20 files changed

+64
-63
lines changed

package-lock.json

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

packages/contentstack-audit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"@contentstack/cli-command": "~1.5.0",
2222
"@oclif/plugin-help": "^6.2.27",
23-
"@contentstack/cli-utilities": "~1.11.1",
23+
"@contentstack/cli-utilities": "~1.11.2",
2424
"@oclif/plugin-plugins": "^5.4.36",
2525
"chalk": "^4.1.2",
2626
"fast-csv": "^4.3.6",

packages/contentstack-bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"@contentstack/cli-cm-seed": "~1.11.1",
2121
"@contentstack/cli-command": "~1.5.0",
22-
"@contentstack/cli-utilities": "~1.11.1",
22+
"@contentstack/cli-utilities": "~1.11.2",
2323
"inquirer": "8.2.6",
2424
"mkdirp": "^1.0.4",
2525
"tar": "^6.2.1 "

packages/contentstack-branches/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@contentstack/cli-command": "~1.5.0",
99
"@oclif/core": "^4.2.7",
10-
"@contentstack/cli-utilities": "~1.11.1",
10+
"@contentstack/cli-utilities": "~1.11.2",
1111
"chalk": "^4.1.2",
1212
"just-diff": "^6.0.2",
1313
"lodash": "^4.17.21"

packages/contentstack-bulk-publish/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
88
"@contentstack/cli-command": "~1.5.0",
9-
"@contentstack/cli-utilities": "~1.11.1",
9+
"@contentstack/cli-utilities": "~1.11.2",
1010
"chalk": "^4.1.2",
1111
"dotenv": "^16.4.7",
1212
"inquirer": "8.2.6",

packages/contentstack-clone/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@contentstack/cli-cm-export": "~1.16.2",
1010
"@contentstack/cli-cm-import": "~1.22.1",
1111
"@contentstack/cli-command": "~1.5.0",
12-
"@contentstack/cli-utilities": "~1.11.1",
12+
"@contentstack/cli-utilities": "~1.11.2",
1313
"chalk": "^4.1.2",
1414
"inquirer": "8.2.6",
1515
"lodash": "^4.17.21",

packages/contentstack-command/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"format": "eslint src/**/*.ts --fix"
1818
},
1919
"dependencies": {
20-
"@contentstack/cli-utilities": "~1.11.1",
20+
"@contentstack/cli-utilities": "~1.11.2",
2121
"contentstack": "^3.25.2"
2222
},
2323
"devDependencies": {

packages/contentstack-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@contentstack/cli-command": "~1.5.0",
25-
"@contentstack/cli-utilities": "~1.11.1",
25+
"@contentstack/cli-utilities": "~1.11.2",
2626
"lodash": "^4.17.21"
2727
},
2828
"devDependencies": {

packages/contentstack-export-to-csv/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
88
"@contentstack/cli-command": "~1.5.0",
9-
"@contentstack/cli-utilities": "~1.11.1",
9+
"@contentstack/cli-utilities": "~1.11.2",
1010
"fast-csv": "^4.3.6",
1111
"inquirer": "8.2.6",
1212
"inquirer-checkbox-plus-prompt": "1.4.2",

packages/contentstack-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@contentstack/cli-command": "~1.5.0",
99
"@contentstack/cli-variants": "~1.2.1",
1010
"@oclif/core": "^4.2.7",
11-
"@contentstack/cli-utilities": "~1.11.1",
11+
"@contentstack/cli-utilities": "~1.11.2",
1212
"async": "^3.2.6",
1313
"big-json": "^3.2.0",
1414
"bluebird": "^3.7.2",

packages/contentstack-import-setup/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@contentstack/cli-command": "~1.5.0",
99
"@oclif/core": "^4.2.7",
10-
"@contentstack/cli-utilities": "~1.11.1",
10+
"@contentstack/cli-utilities": "~1.11.2",
1111
"big-json": "^3.2.0",
1212
"chalk": "^4.1.2",
1313
"fs-extra": "^11.1.1",

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@contentstack/cli-audit": "~1.12.1",
99
"@contentstack/cli-command": "~1.5.0",
10-
"@contentstack/cli-utilities": "~1.11.1",
10+
"@contentstack/cli-utilities": "~1.11.2",
1111
"@contentstack/management": "~1.20.2",
1212
"@contentstack/cli-variants": "~1.2.1",
1313
"@oclif/core": "^4.2.7",

packages/contentstack-migrate-rte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
88
"@contentstack/cli-command": "~1.5.0",
9-
"@contentstack/cli-utilities": "~1.11.1",
9+
"@contentstack/cli-utilities": "~1.11.2",
1010
"@contentstack/json-rte-serializer": "~2.0.11",
1111
"collapse-whitespace": "^1.1.7",
1212
"chalk": "^4.1.2",

packages/contentstack-migration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"bugs": "https://github.com/contentstack/cli/issues",
66
"dependencies": {
77
"@contentstack/cli-command": "~1.5.0",
8-
"@contentstack/cli-utilities": "~1.11.1",
8+
"@contentstack/cli-utilities": "~1.11.2",
99
"async": "^3.2.6",
1010
"callsites": "^3.1.0",
1111
"cardinal": "^2.1.1",

packages/contentstack-seed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@contentstack/cli-cm-import": "~1.22.1",
99
"@contentstack/cli-command": "~1.5.0",
10-
"@contentstack/cli-utilities": "~1.11.1",
10+
"@contentstack/cli-utilities": "~1.11.2",
1111
"@contentstack/management": "~1.20.2",
1212
"inquirer": "8.2.6",
1313
"mkdirp": "^1.0.4",

packages/contentstack-utilities/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-utilities",
3-
"version": "1.11.1",
3+
"version": "1.11.2",
44
"description": "Utilities for contentstack projects",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

packages/contentstack-utilities/src/authentication-handler.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ class AuthenticationHandler {
5353

5454
async refreshAccessToken(error: any, maxRetryCount = 1): Promise<void> {
5555
if (error.response && error.response.status) {
56-
console.error(error.response);
57-
if (maxRetryCount >= 3) {
58-
ux.print('Max retry count reached, please login to proceed', {
59-
color: 'yellow',
60-
});
61-
process.exit(1);
62-
}
63-
64-
maxRetryCount++; // Increment for the next retry attempt
65-
6656
switch (error.response.status) {
6757
case 401:
6858
// NOTE: Refresh the token if the type is OAuth.
@@ -74,12 +64,25 @@ class AuthenticationHandler {
7464
if (u.host) hostName = u.host;
7565
}
7666
hostName = hostName || region.cma;
77-
await this.refreshToken(hostName);
78-
return this.refreshAccessToken(error, maxRetryCount); // Retry after refreshing the token
67+
const refreshed = await this.refreshToken(hostName);
68+
if (refreshed) {
69+
return this.refreshAccessToken(error, maxRetryCount); // Retry after refreshing the token
70+
}
71+
console.log('API(401) case error:-', error.response);
72+
// For Basic Auth, exit immediately without retrying
73+
return;
7974
}
75+
break;
8076

8177
case 429:
8278
case 408:
79+
if (maxRetryCount >= 3) {
80+
ux.print('Max retry count reached, please login to proceed', {
81+
color: 'yellow',
82+
});
83+
process.exit(1);
84+
}
85+
maxRetryCount++; // Increment for the next retry attempt
8386
// These cases require a wait, adding a delay before retrying
8487
await new Promise((resolve) => setTimeout(resolve, 1000)); // wait for 1 second
8588
return this.refreshAccessToken(error, maxRetryCount); // Retry
@@ -93,8 +96,6 @@ class AuthenticationHandler {
9396
refreshToken(hostName: string): Promise<boolean> {
9497
return new Promise<boolean>((resolve) => {
9598
if (this.authType === 'BASIC') {
96-
// NOTE Handle basic auth 401 here
97-
resolve(false);
9899
ux.print('Session timed out, please login to proceed', {
99100
color: 'yellow',
100101
});
@@ -109,10 +110,10 @@ class AuthenticationHandler {
109110
resolve(true);
110111
})
111112
.catch((error: any) => {
113+
console.log(error);
112114
resolve(false);
113115
});
114116
} else {
115-
resolve(false);
116117
ux.print('You do not have the permissions to perform this action, please login to proceed', {
117118
color: 'yellow',
118119
});

packages/contentstack/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3776,7 +3776,7 @@ USAGE
37763776
$ csdx launch:functions [-p <value>] [-d <value>]
37773777
37783778
FLAGS
3779-
-d, --data-dir=<value> [default: /Users/aman.kumar/Documents/cli-repos/cli/packages/contentstack] Current working
3779+
-d, --data-dir=<value> [default: /Users/aman.kumar/Documents/datasync-repo/cli/packages/contentstack] Current working
37803780
directory
37813781
-p, --port=<value> [default: 3000] Port number
37823782

packages/contentstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@contentstack/cli-config": "~1.12.1",
3939
"@contentstack/cli-launch": "^1.8.0",
4040
"@contentstack/cli-migration": "~1.7.2",
41-
"@contentstack/cli-utilities": "~1.11.1",
41+
"@contentstack/cli-utilities": "~1.11.2",
4242
"@contentstack/cli-variants": "~1.2.1",
4343
"@contentstack/management": "~1.20.3",
4444
"@oclif/core": "^4.2.10",

0 commit comments

Comments
 (0)