Docs

API Reference

Complete reference for RetryManager and its public methods.

Factory functions

createRetryer(options?)

Creates and returns a RetryManager instance. Equivalent to new RetryManager(options).

import { createRetryer } from 'axios-retryer';
const retryer = createRetryer({ retries: 3 });

createRetryStrategy(config)

Creates a custom IRetryStrategy from a plain config object.

import { createRetryStrategy } from 'axios-retryer';
const strategy = createRetryStrategy({
  isRetryable: (error) => error.response?.status === 503,
  shouldRetry: (error, attempt, max) => attempt <= max,
  getDelay: (attempt) => attempt * 500,
});

RetryManager instance

Properties

PropertyTypeDescription
axiosInstanceAxiosInstanceThe wrapped Axios instance. Use this for all requests.

Request management

MethodSignatureDescription
cancelRequest(requestId: string) → voidCancel a specific in-flight or queued request by its ID
cancelAllRequests() → voidCancel all in-flight and queued requests

Plugin management

MethodSignatureDescription
use(plugin, before?) → RetryManagerRegister a plugin. Returns the same manager with widened event types — keep that value in your variable (chain .use(a).use(b) or reassign) so on() is typed for every plugin.
unuse(pluginName: string) → voidUnregister a plugin by name, running its cleanup hooks
listPlugins() → {name, version}[]List all registered plugins

Event management

MethodSignatureDescription
on(event, listener) → thisSubscribe to a lifecycle event. Chainable.
off(event, listener) → thisUnsubscribe from an event
triggerAndEmit(event, ...args) → Promise<void>Programmatically trigger hooks and emit events (useful for plugins)

Metrics and diagnostics

MethodSignatureDescription
getMetrics() → RetryMetricsReturns metrics snapshot. Counters are zero without MetricsPlugin.
getTimerStats() → TimerStatsReturns active timer counts for health monitoring
getLogger() → ILoggerReturns the internal logger instance

Lifecycle

MethodDescription
destroy()Full cleanup: cancel all requests, clear all timers, eject interceptors, unregister all plugins. Makes the instance unusable.

RetryMetrics shape

interface RetryMetrics {
  totalRequests: number;
  successfulRetries: number;
  failedRetries: number;
  completelyFailedRequests: number;
  completelyFailedCriticalRequests: number;
  totalRetryAttempts: number;
  averageRetryDelay: number;
  timerHealth: {
    activeTimers: number;
    activeRetryTimers: number;
    healthScore: number;          // 0 = excellent, 100+ = potential leak
  };
}

TimerStats shape

interface TimerStats {
  activeTimers: number;
  activeRetryTimers: number;
}

Request config extension

The __axiosRetryer field on AxiosRequestConfig carries per-request options:

interface AxiosRetryerRequestConfig {
  priority?: AXIOS_RETRYER_REQUEST_PRIORITIES;  // Queue priority
  requestId?: string;                           // Stable ID for cancellation
  retries?: number;                             // Override global retry count
  backoffType?: AXIOS_RETRYER_BACKOFF_TYPES;
  retryableStatuses?: RetryableStatuses;
}

// Usage:
retryer.axiosInstance.get('/api', {
  __axiosRetryer: {
    priority: AXIOS_RETRYER_REQUEST_PRIORITIES.CRITICAL,
    requestId: 'auth-check',
  },
});

Constants

import {
  RETRY_MODES,                        // AUTOMATIC | MANUAL
  AXIOS_RETRYER_REQUEST_PRIORITIES,   // CRITICAL=4, HIGH=2, MEDIUM=1, LOW=0
  AXIOS_RETRYER_BACKOFF_TYPES,        // STATIC | LINEAR | EXPONENTIAL
  AXIOS_RETRYER_HTTP_METHODS,         // GET | POST | PUT | PATCH | DELETE | HEAD | OPTIONS
} from 'axios-retryer';
Plugins →