diff --git a/src/utils.ts b/src/utils.ts index 684495af0..124ed0f96 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -752,17 +752,14 @@ export function getCrypto(): Object { export async function retryNetworkOperation(maxAttempts, callback) { let attempts = 0; - let success = false; let lastConnectionError = null; - let result; - while (!success && attempts < maxAttempts) { + while (attempts < maxAttempts) { try { if (attempts > 0) { const timeout = 1000 * Math.pow(2, attempts); await new Promise(r => setTimeout(r, timeout)); } - result = await callback(); - success = true; + return await callback(); } catch (err) { if (err instanceof ConnectionError) { attempts += 1; @@ -772,9 +769,5 @@ export async function retryNetworkOperation(maxAttempts, callback) { } } } - if (!success) { - throw lastConnectionError; - } else { - return result; - } + throw lastConnectionError; }