Skip to content

@statesync/core


@statesync/core / withRetryReporting

Function: withRetryReporting() ​

ts
function withRetryReporting<T>(provider, options): SnapshotProvider<T>;

Defined in: retry.ts:224

Wraps a SnapshotProvider with retries and reports each intermediate retry attempt via the provided logger and/or onError callback.

This is a convenience wrapper around withRetry that integrates with the state-sync error reporting pipeline. On each retry attempt, it:

  1. Logs a warn-level message via the logger (if provided).
  2. Calls the onError hook (if provided) with a SyncErrorContext.

The final failure (when all retries are exhausted) is still thrown and will be caught by the sync engine, which emits its own getSnapshot error. This wrapper provides visibility into the intermediate retry attempts only.

Type Parameters ​

Type ParameterDescription
TThe snapshot data type carried inside the SnapshotEnvelope.

Parameters ​

ParameterTypeDescription
providerSnapshotProvider<T>The original snapshot provider to wrap with retry and reporting logic.
optionsRetryReportingOptionsConfiguration for retry behavior, logging, and error hooks.

Returns ​

SnapshotProvider<T>

A new SnapshotProvider with retry and reporting behavior.

Throws ​

The last error from the provider if all retry attempts are exhausted.

Example ​

ts
import { withRetryReporting } from '@statesync/core';

const provider = withRetryReporting(originalProvider, {
  topic: 'user-profile',
  policy: { maxAttempts: 5 },
  logger: consoleLogger,
  onError: (ctx) => metrics.increment('sync.retry', { topic: ctx.topic }),
});

Released under the MIT License.