UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

45 lines 2.1 kB
/** * Retry helpers for SDK API calls. * * Two consumers: * 1. `attachRetryInterceptor` — axios response interceptor used inside * LunarIndexerClient. One install per axios instance covers every method. * 2. `retry` — generic wrapper for ad-hoc `axios.post(...)` callsites in * actions that don't go through a shared axios instance. * * Policy: * - 3 attempts (initial + 2 retries) by default * - Exponential backoff: 250ms → 500ms (capped at 5s) * - Retry only network errors / timeouts / 5xx; never retry 4xx (incl. 404 — * retrying a deterministic "not found" wastes time and amplifies log noise) * - After retries exhaust, the last error propagates to the caller's try/catch * where the existing `environment.onError(...)` wiring picks it up */ import { type AxiosInstance } from "axios"; export interface RetryOptions { maxAttempts?: number; initialDelay?: number; maxDelay?: number; } /** * Decide whether an error represents a transient failure worth retrying. * - Axios network errors (no `response`) → retry (server unreachable, timeout) * - 5xx responses → retry (server hiccup) * - 4xx responses (incl. 404) → do NOT retry (deterministic, won't change) * - Non-axios errors (parse errors, code bugs) → do NOT retry */ export declare function isRetriableError(error: unknown): boolean; /** * Attach a retry-on-failure interceptor to an axios instance. Every request * made through this instance is retried up to `maxAttempts` times when the * failure is retriable. Per-config state is tracked on a WeakMap so we don't * pollute the public axios config shape. */ export declare function attachRetryInterceptor(instance: AxiosInstance, options?: RetryOptions): void; /** * Generic wrapper for individual axios calls (e.g. raw `axios.post(...)` in * action files that don't share a configured instance). Mirrors the * interceptor's policy: retry transient failures, fail fast on 4xx. */ export declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>; //# sourceMappingURL=retry.d.ts.map