Core - v1.3.1
    Preparing search index...

    Class Retry

    A bounded retry with exponential backoff.

    Bounded is the load-bearing word. A scheduled job runs against a wall-clock budget, and an unbounded retry turns one unreachable dependency into an invocation that never ends.

    The kernel has declared the retry policy since 1.1.0: delivery.retries and delivery.retryBackoffMs are in systemDefaults. Until this class, nothing in the package read them, so every consumer that wanted to honour them had to write the loop that does. This is that loop, beside the settings it reads.

    It reads them inside each call rather than at module scope. Resolving at module scope runs before the application's configure and throws ConfigurationError on startup.

    Nothing here names a transport. The default judgement recognises an HTTP failure by shape — an Error carrying a numeric status — rather than by class, so this package takes no dependency on the client that threw it. A caller with its own non-retryable failures, such as a validation error, supplies isRetryable and defers to Retry.isRetryable for the rest.

    Retry only what is safe to repeat. Replaying an operation that writes needs that write to be idempotent, which is a promise this class cannot make for the caller.

    const body = await Retry.run(() => client.get(url), { logger: log, event: 'rates.retry' })
    

    Bayu Dwiyan Satria

    1.3.1

    1.3.1

    Index
    • The default judgement on whether a failure is transient.

      Parameters

      • error: unknown

        The thrown value.

      Returns boolean

      true when another attempt is reasonable.

      An abort or a timeout is not retryable: the caller's own timeout already spent the budget it allowed.

      An Error with a numeric status is read as an HTTP failure, and retried only for 429 and the 5xx gateway family.

      Anything else is treated as a network failure and retried, which is the safe reading — fetch rejects for DNS, TLS and connection resets, and all three are worth a second look.

    • Runs an operation, retrying failures judged transient.

      Type Parameters

      • T

        The operation's result.

      Parameters

      • operation: () => Promise<T>

        The work to attempt. Must be safe to run more than once.

      • options: RetryOptions = {}

        Overrides for the resolved delivery defaults.

      Returns Promise<T>

      Whatever the operation returned.

      Backoff doubles: with the shipped defaults that is one attempt, 250 ms, a second, 500 ms, a third. The last failure is rethrown unchanged, so the caller sees the real cause rather than a wrapper.

      The final failure, once the budget is spent or the failure is not retryable.

      ConfigurationError When delivery is not registered and either attempts or backoffMs was left to default.