promise-retry: only print stack on last attempt

This commit is contained in:
Girish Ramakrishnan
2025-08-05 14:37:24 +02:00
parent 5992658164
commit 70cf212178
+1 -1
View File
@@ -16,9 +16,9 @@ async function promiseRetry(options, asyncFunction) {
try {
return await asyncFunction(i+1 /* attempt */);
} catch (error) {
if (options.debug) options.debug(`Attempt ${i+1} failed. Will retry: ${error.message} ${i === times-1 ? error.stack : ''}`); // only print stack on last error
if (i === times - 1) throw error;
if (options.retry && !options.retry(error)) throw error; // no more retry
if (options.debug) options.debug(`Attempt ${i+1} failed. Will retry: ${error.message} ${error.stack}`);
await timers.setTimeout(interval);
}
}