@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:
- Logs a
warn-level message via the logger (if provided). - Calls the
onErrorhook (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 Parameter | Description |
|---|---|
T | The snapshot data type carried inside the SnapshotEnvelope. |
Parameters
| Parameter | Type | Description |
|---|---|---|
provider | SnapshotProvider<T> | The original snapshot provider to wrap with retry and reporting logic. |
options | RetryReportingOptions | Configuration for retry behavior, logging, and error hooks. |
Returns
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 }),
});