Retries with got #2065
-
|
New got user here. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I'm not sure but from the documentation I understand that when providing your own |
Beta Was this translation helpful? Give feedback.
-
|
When you provide a custom The issue is that if your const gotInstance = got.extend({
retry: {
limit: 5,
calculateDelay({ computedValue, error }) {
// IMPORTANT: Return 0 when default logic says don't retry
if (computedValue === 0) {
return 0;
}
// Your custom delay logic
return computedValue * 2; // Example: double the delay
},
methods: ['GET']
}
});Alternatively, use const gotInstance = got.extend({
retry: {
limit: 5,
enforceRetryRules: true, // Enforce rules BEFORE calling calculateDelay
calculateDelay({ computedValue }) {
// With enforceRetryRules: true, this is only called when retry is allowed
return computedValue * 2;
},
methods: ['GET']
}
});When |
Beta Was this translation helpful? Give feedback.
When you provide a custom
calculateDelayfunction, you take full control of retry logic. Thelimitoption is only automatically enforced if you checkcomputedValuein your function.The issue is that if your
calculateDelayalways returns a positive number, retries will continue indefinitely regardless of thelimit. You must checkcomputedValueto respect the default retry rules: