mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-21 11:09:30 -07:00
Fix retry count display in doFetch
This commit is contained in:
@@ -181,9 +181,9 @@ const fetchAsync = async (_url, responseType, _params = {}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// fetch with retry and back-off
|
// fetch with retry and back-off
|
||||||
const doFetch = (url, params) => new Promise((resolve, reject) => {
|
const doFetch = (url, params, originalRetryCount = null) => new Promise((resolve, reject) => {
|
||||||
// Store the original retry count for logging purposes
|
// On the first call, store the retry count for later logging
|
||||||
const originalRetryCount = params.retryCount;
|
const initialRetryCount = originalRetryCount ?? params.retryCount;
|
||||||
|
|
||||||
// Create AbortController for timeout
|
// Create AbortController for timeout
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
@@ -206,11 +206,11 @@ const doFetch = (url, params) => new Promise((resolve, reject) => {
|
|||||||
return reject(new Error('Invalid retry parameters'));
|
return reject(new Error('Invalid retry parameters'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const retryAttempt = originalRetryCount - params.retryCount + 1;
|
const retryAttempt = initialRetryCount - params.retryCount + 1;
|
||||||
const remainingRetries = params.retryCount - 1;
|
const remainingRetries = params.retryCount - 1;
|
||||||
const delayMs = retryDelay(retryAttempt);
|
const delayMs = retryDelay(retryAttempt);
|
||||||
|
|
||||||
console.warn(`🔄 Retry ${retryAttempt}/${originalRetryCount} for ${url} - ${reason} (retrying in ${delayMs}ms, ${remainingRetries} retr${remainingRetries === 1 ? 'y' : 'ies'} left)`);
|
console.warn(`🔄 Retry ${retryAttempt}/${initialRetryCount} for ${url} - ${reason} (retrying in ${delayMs}ms, ${remainingRetries} retr${remainingRetries === 1 ? 'y' : 'ies'} left)`);
|
||||||
|
|
||||||
// call the "still waiting" function on first retry
|
// call the "still waiting" function on first retry
|
||||||
if (params && params.stillWaiting && typeof params.stillWaiting === 'function' && retryAttempt === 1) {
|
if (params && params.stillWaiting && typeof params.stillWaiting === 'function' && retryAttempt === 1) {
|
||||||
@@ -227,7 +227,7 @@ const doFetch = (url, params) => new Promise((resolve, reject) => {
|
|||||||
};
|
};
|
||||||
// Use setTimeout directly instead of the delay wrapper to avoid Promise resolution issues
|
// Use setTimeout directly instead of the delay wrapper to avoid Promise resolution issues
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
doFetch(url, newParams).then(resolve).catch(reject);
|
doFetch(url, newParams, initialRetryCount).then(resolve).catch(reject);
|
||||||
}, delayMs);
|
}, delayMs);
|
||||||
return undefined; // Explicit return for linter
|
return undefined; // Explicit return for linter
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user