Skip to main content
Logo Light

Welcome to Runtry

A modern, type-safe error handling library that makes async operations predictable and resilient.

Features

No more try-catch blocks. Get discriminated unions with full TypeScript support.
const result = await runner.run(() => apiCall());
if (result.ok) {
  // TypeScript knows data is available
  console.log(result.data);
}
Built-in exponential backoff with jitter to prevent thundering herd.
await runner.run(() => unstableApi(), {
  retries: 3,
  retryDelay: (attempt) => Math.pow(2, attempt) * 1000,
  jitter: true
});
Run multiple operations with controlled parallelism.
await runner.all(tasks, { 
  concurrency: 5,
  mode: 'fail-fast' 
});
First-class support for AbortController and graceful cancellation.
await runner.run(() => fetch('/api', { signal }), {
  ignoreAbort: true
});

Installation

npm install runtry

Quick Example

import { createRunner } from 'runtry';

const runner = createRunner();

const result = await runner.run(
  () => fetch('https://api.example.com/users'),
  {
    retries: 3,
    retryDelay: 1000,
    onError: (error) => console.error(error)
  }
);

if (result.ok) {
  const users = await result.data.json();
  console.log(users);
}
Pro tip: Use createRunner() once and reuse it across your app for consistent error handling.

Next Steps