Skip to content

Add retryAttempt to FetchContext #536

@MrBartusek

Description

@MrBartusek

Describe the feature

PR #372 added the ability to pass a callback to retryDelay, which should enable exponential backoff, but currently it's tricky to implement. I couldn't find an option to get the current attempt in this callback. The mentioned PR calls for context.options.retryAttempt, which doesn't exist.

I am currently using a workaround:

function exponentialBackoff(baseRetries: number, baseDelay = 1_000) {
    return (context: FetchContext<any, 'json'>) => {
      const retryLeft = context.options.retry || 0
      const currentRetry = baseRetries - retryLeft
      return baseDelay * 2 ** currentRetry
    }
  }

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions