You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Throwing an error in onRetry seems like a weird behavior to me.
constretry=require("async-retry");(async()=>{try{awaitretry((bail,attempt)=>{thrownewError(`inside error at ${attempt}`);},{onRetry: (e,attempt)=>{console.error(e.message);thrownewError(`onRetry error at ${attempt}`);},},);}catch(e){console.error(e.message);}})();
Result:
inside error at 1
onRetry error at 1
inside error at 2
/home/xxxxx/playground.js:12
throw new Error(`onRetry error at ${attempt}`);
^
Error: onRetry error at 2
at Object.onRetry (/home/xxxxx/playground.js:12:17)
at onError (/home/xxxxx/node_modules/async-retry/lib/index.js:33:17)
at RetryOperation.runAttempt [as _fn] (/home/xxxxx/node_modules/async-retry/lib/index.js:43:9)
at Timeout._onTimeout (/home/xxxxx/node_modules/retry/lib/retry_operation.js:81:10)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
I expected that it caught once without retry like:
inside error at 1
onRetry error at 1
(finish)
otherwise, with retry like:
inside error at 1
inside error at 2
inside error at 3
inside error at 4
inside error at 5
inside error at 6
onRetry error at 6
(finish)
Is this a bug?
The text was updated successfully, but these errors were encountered:
Too bad this library isn't being maintained anymore. Ended up fixing this by wrapping the function to be retried with my own try/catch that calls what I had in onRetry, eg.
asyncwithRetry(fn){letattempt=0;constwrapper=async(...params)=>{try{attempt++;returnawaitfn(...params);}catch(e){console.warn(`Retrying attempt ${attempt}`,e);// what I would have had in my onRetryif(e.code==401||e.code==400){awaitmaybeThrowsError();}// always throw original errorthrowe;}}returnawaitretry(wrapper,{retries: 1});}
Throwing an error in
onRetry
seems like a weird behavior to me.Result:
I expected that it caught once without retry like:
otherwise, with retry like:
Is this a bug?
The text was updated successfully, but these errors were encountered: