Skip to content
Discussion options

You must be logged in to vote

When you provide a custom calculateDelay function, you take full control of retry logic. The limit option is only automatically enforced if you check computedValue in your function.

The issue is that if your calculateDelay always returns a positive number, retries will continue indefinitely regardless of the limit. You must check computedValue to respect the default retry rules:

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

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants