Unified Error Handling
unified-error-handling is a zero-dependency TypeScript library that puts multiple error-tracking services behind one provider-less API. You initialize the store once, pick an adapter with useAdapter('sentry') (or firebase, datadog, bugsnag, rollbar, logrocket, raygun, appcenter, the built-in console, or your own), and every captureError() call from anywhere in your app is normalized, enriched, and routed to that service.
It is published on npm as unified-error-handling and is MIT-licensed.
What it gives you
- One API across services. Switch from the console adapter in development to Sentry in production by changing a single
useAdapter()call — yourcaptureError()sites never change. - A zero-dependency core. Nothing is bundled for a service you do not use. Each SDK is pulled in with a dynamic
import()only when its adapter is activated. - A provider-less store.
errorStoreis a singleton, so you can capture errors from a utility, a web worker, a Vue component, or plain JavaScript — not only from inside a React tree. - Rich context. Automatic device info, a rolling breadcrumb trail, user/tags/extra context, and a
beforeSendhook to filter or scrub errors before they leave the browser. - Resilience. Errors raised while offline are queued and flushed on reconnect. Optional interceptors capture
console.errorand failed network requests; global handlers catch uncaught errors and unhandled rejections. - An optional React layer. A separate
unified-error-handling/reactentry point adds anErrorBoundary, awithErrorBoundaryHOC, and hooks. React is an optional peer dependency.
What it does NOT do
Honest framing matters more than a long feature list.
- It is not itself an error-tracking backend. Adapters forward your errors to a third-party service (or your own endpoint via a custom adapter); the library does not store or display errors on its own.
- It does not install the service SDKs for you. To use the Sentry adapter you install
@sentry/browseryourself; the library loads it dynamically and tells you exactly what to install if it is missing. - It dispatches each error to the single active adapter (the last one passed to
useAdapter()), not to all registered adapters at once. Switching adapters re-points the active one. - The built-in interceptors and global handlers are browser-oriented (they rely on
window). In Node.js the core store, manualcaptureError(), and custom adapters work, butwindow-based capture does not.
Where to go next
- Installation — install the package and the optional per-service SDKs.
- Quick Start — capture your first error in five minutes.
- Configuration — the full
initialize()config shape. - Providers overview — the adapter capability matrix.
- Core API — every exported function.
Built and maintained by Ahsan Mahmood (GitHub · npm).