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
import pRetry from 'p-retry';
const run = async () => {
const response = await fetch('https://sindresorhus.com/unicorn');
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json();
};
const result = await pRetry(run, {
onFailedAttempt: error => {
console.log(`Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`);
// 1st request => Attempt 1 failed. There are 4 retries left.
// 2nd request => Attempt 2 failed. There are 3 retries left.
// …
},
retries: 5
});
console.log(result);
The comments say
// 1st request => Attempt 1 failed. There are 4 retries left.
// 2nd request => Attempt 2 failed. There are 3 retries left.
But this is neither true nor the actual output. When the 1st attempt fails, there are still 5 retries left, because the retries does not count the first try as a re-try.
Fortunately this issue is not a bug of the code, but a mistake on the documentation.
The text was updated successfully, but these errors were encountered:
issuefiler
changed the title
The documentation of onFailedAttempt(error) is incorrect.
The documentation of onFailedAttempt(error) is incorrect and misleading.
May 29, 2022
This is the example code on the readme.md.
The comments say
But this is neither true nor the actual output. When the 1st attempt fails, there are still 5 retries left, because the
retries
does not count the first try as a re-try.Fortunately this issue is not a bug of the code, but a mistake on the documentation.
The actual output for the
retries
of5
is:onFailedAttempt({attemptNumber: 1, retriesLeft: 5})
onFailedAttempt({attemptNumber: 2, retriesLeft: 4})
onFailedAttempt({attemptNumber: 6, retriesLeft: 0})
The text was updated successfully, but these errors were encountered: