Skip to content

[DX-2996], added logs to debug the variant export issue #1928

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

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
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
12 changes: 11 additions & 1 deletion packages/contentstack-utilities/src/authentication-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class AuthenticationHandler {
}

async refreshAccessToken(error: any, maxRetryCount = 1): Promise<void> {
console.log('🚀 ~ Refresh attempt:', maxRetryCount);
console.log('🚀 ~ Error status:', error.response?.status);
console.log('🚀 ~ Error details:', error.response?.data);
if (error.response && error.response.status) {
if (maxRetryCount >= 3) {
ux.print('Max retry count reached, please login to proceed', {
Expand All @@ -73,6 +76,8 @@ class AuthenticationHandler {
if (u.host) hostName = u.host;
}
hostName = hostName || region.cma;
console.log('🚀 ~ Region config:', configHandler.get('region'));
console.log('🚀 ~ Current OAuth token:', configHandler.get('oauthAccessToken'));
await this.refreshToken(hostName);
return this.refreshAccessToken(error, maxRetryCount); // Retry after refreshing the token
}
Expand All @@ -90,6 +95,9 @@ class AuthenticationHandler {
}

refreshToken(hostName: string): Promise<boolean> {
console.log('🚀 ~ Attempting to refresh token for host:', hostName);
console.log('🚀 ~ Auth type:', this.authType);

return new Promise<boolean>((resolve) => {
if (this.authType === 'BASIC') {
// NOTE Handle basic auth 401 here
Expand All @@ -99,16 +107,18 @@ class AuthenticationHandler {
});
process.exit();
} else if (this.authType === 'OAUTH') {
console.log('🚀 ~ Starting OAuth refresh...');
authHandler.host = hostName;
// NOTE Handle OAuth refresh token
authHandler
.compareOAuthExpiry(true)
.then(() => {
console.log('🚀 ~ Token refreshed successfully');
this.token = `Bearer ${configHandler.get('oauthAccessToken')}`;
resolve(true);
})
.catch((error: any) => {
console.log(error);
console.log('🚀 ~ Token refresh failed:', error);
resolve(false);
});
} else {
Expand Down
Loading