datadog-ux-utils Documentation - v1.0.0
    Preparing search index...

    Function retry

    • Retry an async operation with backoff/jitter.

      Type Parameters

      • T

      Parameters

      • label: string

        Unique label for telemetry (e.g., "GET /api/items")

      • op: () => Promise<T>

        Function returning a Promise

      • Optionalcfg: RetryConfig

        RetryConfig

      Returns Promise<T>

      The resolved value from the operation, or throws after all retries fail.

      // Retry GET request up to 5 times, with exponential backoff starting at 300ms
      const data = await retry("GET /api/patients", async () => {
      const res = await fetch("/api/patients");
      if (!res.ok) throw new Error(`Status ${res.status}`);
      return res.json();
      }, {
      retries: 5,
      baseMs: 300,
      jitter: true,
      report: true // enable DataDog telemetry at default 10% sampling
      });