Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

TypeScript · 40 lines · 1.1 KiB · at 8396947

export type HttpResponse = { status: number; body: string };/** What the fetcher's promise rejects with on a network failure. */export class NetworkError extends Error {  public readonly kind = "network" as const;  constructor(message: string) {    super(message);  }}export type Fetcher = (url: string) => Promise<HttpResponse>;export type RetryOptions = {  retries: number;  baseDelayMs: number;  sleep: (ms: number) => Promise<void>;};export class HttpError extends Error {  public readonly kind = "http" as const;  constructor(public readonly status: number) {    super(`http ${status}`);  }}export class ExhaustedError extends Error {  public readonly kind = "exhausted" as const;  constructor(    public readonly attempts: number,    /** Status of the final attempt if it was 5xx; undefined if it was a network error. */    public readonly lastStatus?: number,  ) {    super(`exhausted after ${attempts} attempts`);  }}/** Resolves with the response body. Rejects with HttpError or ExhaustedError. */export async function retryFetch(fetcher: Fetcher, url: string, options: RetryOptions): Promise<string> {  // TODO}