Import
What it does
ErrorBoundary provides a centralized place to handle, normalize, retry, and log errors. Plain Error instances are automatically converted into typed AppError subclasses using keyword detection, so you always work with structured errors that carry a status code, error code, and context.
ErrorBoundary
Constructor
ErrorBoundaryConfig
Methods
ErrorContext
Error classes
All error classes extend AppError, which extends Error.
AppError
Typed error subclasses
Automatic error normalization
When ErrorBoundary receives a plain Error, it inspects the message and converts it to the closest typed subclass:
Retryable errors
ErrorBoundary.execute() automatically retries when isRetryable returns true:
- Status
408 (timeout)
- Status
429 (rate limit)
- Status
5xx (server errors)
Non-retryable errors (like 400, 401, 403, 404, 409) fail immediately without retrying.
Examples
Basic error handling
Wrapping functions
Custom error handlers
Throwing typed errors
Error report
Global error boundary
A singleton ErrorBoundary for app-wide error handling:
getGlobalErrorBoundary() returns the same instance on every call. Pass a config only on the first call — subsequent calls ignore the config argument.
The global boundary registers unhandledrejection and onerror listeners automatically. Call resetGlobalErrorBoundary() in test teardown to avoid listener leaks.