Skip to content

Commit

Permalink
SDA-4737 - Add abort & handle network changed use case
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranNiranjan committed Dec 4, 2024
1 parent 3e35d23 commit 01d7312
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/app/main-api-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ let formattedPodUrl = '';
let credentialsPromise;
const credentialsPromiseRefHolder: { [key: string]: any } = {};
const BROWSER_LOGIN_RETRY = 15 * 1000; // 15sec
const BROWSER_LOGIN_ABORT_TIMEOUT = 10 * 1000; // 10sec

/**
* Handle API related ipc messages from renderers. Only messages from windows
Expand Down Expand Up @@ -795,11 +796,16 @@ const loadPodUrl = (() => {
};
}

const controller = new AbortController();
const timeout = setTimeout(
() => controller.abort(),
BROWSER_LOGIN_ABORT_TIMEOUT,
);
try {
const response = await fetch(
`${formattedPodUrl}${AUTH_STATUS_PATH}`,
onLogin,
);
const response = await fetch(`${formattedPodUrl}${AUTH_STATUS_PATH}`, {
...onLogin,
signal: controller.signal,
});
const authResponse = (await response.json()) as IAuthResponse;
logger.info('main-api-handler: check auth response', authResponse);

Expand Down Expand Up @@ -854,7 +860,7 @@ const loadPodUrl = (() => {
error.code,
);
retryCount++;
if (retryCount < maxRetries) {
if (retryCount < maxRetries || error.code === 'ERR_NETWORK_CHANGED') {
retryTimeoutId = setTimeout(attemptFetch, BROWSER_LOGIN_RETRY);
} else {
logger.error(
Expand All @@ -864,6 +870,10 @@ const loadPodUrl = (() => {
setLoginRetryState(isRetryInProgress);
}
}
} finally {
if (timeout) {
clearTimeout(timeout);
}
}
};

Expand Down

0 comments on commit 01d7312

Please sign in to comment.