or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Resilient Fetch Wrapper

A utility for performing HTTP GET requests with automatic retries, exponential backoff, and attempt reporting so callers can reason about transient failures.

Capabilities

Retries transient failures

  • When the first request returns 503 and the next returns 200 with body "ok", the function resolves with that body and reports attempt count 2. @test

Backoff reporting

  • With initialDelayMs of 100 and backoffFactor of 2, the onAttempt hook receives delays of 100 then 200 milliseconds for attempts 2 and 3 before a third-attempt success. @test

Attempt metadata

  • After retries succeed, the result exposes the final status, body text, response headers, and an attempts count that matches the retry-aware metadata from the HTTP client (for example, the x-fetch-attempts response header). @test

Exhausts retry budget

  • When every attempt fails with a timeout error, the promise rejects with that final error and reports total attempts equal to maxAttempts. @test

Implementation

@generates

API

/**
 * Perform a GET request with configurable retries/backoff and attempt tracking.
 * @param {string|URL} url - Target resource.
 * @param {{
 *   maxAttempts?: number,
 *   initialDelayMs?: number,
 *   backoffFactor?: number,
 *   onAttempt?: (attempt: number, reason: Error|Response, nextDelayMs: number) => void,
 * }} [options]
 * Attempts are counted inclusively (the first request is attempt 1).
 * @returns {Promise<{status: number, body: string, attempts: number, headers: Record<string, string>}>}
 */
export async function fetchWithResilience(url, options);

Dependencies { .dependencies }

make-fetch-happen { .dependency }

Provides a fetch-compatible HTTP client with automatic retry/backoff.