Function performActionWithRetryAfterRecovery

  • Perform an action optimistically. If it fails the first time, first initiate a provided recovery procedure, then retry the action. If it fails again, throw the error.

    This is useful for actions that may fail due to recoverable errors, such as an expired token that can be refreshed. In this case, the recovery procedure would refresh the token.

    Type Parameters

    • T

    Parameters

    • performAction: (() => Promise<T>)

      The action to perform.

        • (): Promise<T>
        • Returns Promise<T>

    • recoveryProcedure: (() => Promise<unknown>)

      The recovery procedure to perform if the action fails the first time.

        • (): Promise<unknown>
        • Returns Promise<unknown>

    • retries: number = 1

      The number of times to retry the action if an error happens.

    Returns Promise<T>

    The result of the action.