Skip to main content

Overview

ErrorBoundary provides utilities for handling and recovering from errors gracefully.

Import

import { ErrorBoundary } from "bytekit";
// or
import { ErrorBoundary } from "bytekit/error-boundary";

Usage

const boundary = new ErrorBoundary({
  onError: (error) => {
    console.error("Caught error:", error);
  },
  fallback: () => {
    return { error: true, message: "Something went wrong" };
  }
});

const result = await boundary.execute(async () => {
  return await riskyOperation();
});

See Also