Skip to main content

Custom Adapter

The custom adapter forwards captured errors to any backend you control — your own API, a log pipeline, navigator.sendBeacon, a message queue. It needs no SDK; you supply a send callback.

Activate

The fastest path is createAdapter(), which builds and registers the adapter in one call:

import { createAdapter, useAdapter, captureError } from 'unified-error-handling';

createAdapter('my-backend', {
async send(error, context) {
await fetch('https://api.example.com/errors', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ error, context }),
});
},
});

await useAdapter('my-backend');
captureError(new Error('Boom')); // POSTed to your API

Config (CustomAdapterConfig)

FieldRequiredCalled when
send(error, context)yesThe store dispatches an error here.
initialize()noThe adapter is activated.
setContext(context)noThe store context changes.
addBreadcrumb(breadcrumb)noA breadcrumb is added.
flush()noflush() is called.
close()noThe adapter is removed or the store is reset.

Why it is the zero-cost option

A custom adapter lets you keep error data on infrastructure you already run — no third-party account, no extra SDK, no bundled dependency. It is also the recommended way to fan errors out to several destinations at once (do the multiplexing inside your send).

See the full custom adapters guide for createCustomAdapter(), lifecycle details, and tips.