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
| Property | Type | Description |
axiosInstance | AxiosInstance | The wrapped Axios instance. Use this for all requests. |
Request management
| Method | Signature | Description |
cancelRequest | (requestId: string) → void | Cancel a specific in-flight or queued request by its ID |
cancelAllRequests | () → void | Cancel all in-flight and queued requests |
Plugin management
| Method | Signature | Description |
use | (plugin, before?) → RetryManager | Register 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) → void | Unregister a plugin by name, running its cleanup hooks |
listPlugins | () → {name, version}[] | List all registered plugins |
Event management
| Method | Signature | Description |
on | (event, listener) → this | Subscribe to a lifecycle event. Chainable. |
off | (event, listener) → this | Unsubscribe from an event |
triggerAndEmit | (event, ...args) → Promise<void> | Programmatically trigger hooks and emit events (useful for plugins) |
Metrics and diagnostics
| Method | Signature | Description |
getMetrics | () → RetryMetrics | Returns metrics snapshot. Counters are zero without MetricsPlugin. |
getTimerStats | () → TimerStats | Returns active timer counts for health monitoring |
getLogger | () → ILogger | Returns the internal logger instance |
Lifecycle
| Method | Description |
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';