Skip to main content

Reuse an instance

import trybox from "trybox";
export const runner = trybox({ ignoreAbort: true });

Centralize mapError

const runner = trybox({ mapError: (e) => ({ ...e, message: e.message }) });

Limit retries

await runner.run(() => fetch("/api"), {
  retries: 3,
  shouldRetry: (attempt, e, ctx) => e.code !== "ABORTED" && ctx.elapsedTime < 5000,
});

Use jitter and backoff

await runner.run(() => fetch("/api"), { retryDelay: 300, jitter: 0.5, backoffStrategy: "exponential" });