Retry Modes
axios-retryer supports two modes: Automatic (default) transparently retries failures; Manual stops after the first attempt and lets you decide when to replay.
Automatic mode
The default. Transient failures are retried up to retries times with configurable backoff, completely transparent to your application code.
import { createRetryer, RETRY_MODES, AXIOS_RETRYER_BACKOFF_TYPES } from 'axios-retryer';
const retryer = createRetryer({
mode: RETRY_MODES.AUTOMATIC, // default, can omit
retries: 3,
backoffType: AXIOS_RETRYER_BACKOFF_TYPES.EXPONENTIAL,
retryableStatuses: [408, 429, [500, 599] as const],
});
// This GET will retry up to 3 times on 5xx / 429 / timeout
const { data } = await retryer.axiosInstance.get('/api/products'); What triggers a retry
- Response status code matches
retryableStatuses - Request method is in
retryableMethods(default: GET, HEAD, OPTIONS) - Network error with no response
- Custom
retryStrategy.isRetryable()returnstrue
Manual mode
In manual mode the retry manager does not automatically retry. Each request either succeeds on the first attempt or fails immediately. Add ManualRetryPlugin when you want failed requests stored and replayed later — for example after reconnecting to the network.
import { createRetryer, RETRY_MODES } from 'axios-retryer';
import { createManualRetryPlugin } from 'axios-retryer/plugins/ManualRetryPlugin';
const manualRetry = createManualRetryPlugin({
maxRequestsToStore: 50,
manualRetryMaxAge: 5 * 60_000, // Discard stored requests after 5 min
});
const retryer = createRetryer({ mode: RETRY_MODES.MANUAL }).use(manualRetry);
// Request fails → stored in ManualRetryPlugin
try {
await retryer.axiosInstance.get('/api/data');
} catch {
console.log('Failed — stored for later replay');
}
// Later — replay all stored failures
const results = await manualRetry.retryFailedRequests();
console.log(`${results.length} requests replayed`); Offline / reconnect pattern
window.addEventListener('online', async () => {
const results = await manualRetry.retryFailedRequests();
showToast(`Synced ${results.length} pending request(s)`);
}); Choosing a mode
| Scenario | Mode |
|---|---|
| Standard API client — just handle transient errors | AUTOMATIC |
| You want to surface errors to the user and let them retry | MANUAL |
| Offline-first SPA — queue when offline, sync on reconnect | MANUAL + ManualRetryPlugin |
| Background worker that should keep trying indefinitely | AUTOMATIC with high retries |
RETRY_MODES.MANUAL alone means "don't retry automatically." You still get the concurrency queue and priority system — just no automatic replay. Add ManualRetryPlugin only when you need stored replay functionality.