Throw previous error if there's a timeout
cdeevfrr opened this issue · comments
Right now, code like this will actually throw the error 'RetryOperation timeout occurred' which originates in node-retry. It should throw the error I made ("HI" + Math.random()
), but doesn't because of a timeout error.
import * as retry from 'async-retry'
async function throwsErrors(){
await delay(1000)
throw new Error("HI" + Math.random())
}
retry(
async (bail, attempt) => {
await throwsErrors()
} , {
maxRetryTime: 100,
minTimeout: 2,
randomize: true,
retries: 100,
onRetry: console.log
}
).then(console.log)
async function delay(milliseconds: number) {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
I made an issue in node-retry that describes why this happens in detail, but the gist is that if you call retryOperation.retry(err)
and there's a timeout error, node-retry drops err
. I'm not sure if this is something that node-retry needs to support or if it's something that you can/should handle here.
We created this PR on node-retry, though I'm not sure how long it'll take until it gets looked at
tim-kos/node-retry#71
Has anyone had a chance to look at this?