Plugins
The core stays lean. Plugins are independent, tree-shakeable entry points you add only when you need them. Each plugin has its own documented import path.
Import from focused paths like axios-retryer/plugins/TokenRefreshPlugin so bundlers tree-shake unused plugins. The convenience barrel axios-retryer/plugins bundles everything unconditionally and will be removed in v3.
Follow the single recommended repo pattern for plugin authoring: orchestrator class, focused folders, explicit events, and isolated state boundaries. See Creating Plugins.
Registering multiple plugins
use() returns the same manager instance and widens the TypeScript event map.
Chain plugins on one expression (or reassign each use() result) so on() knows about every plugin’s events.
See Events for the typing rules and an optional RetryManager<YourComposedEvents> pattern.
import { createRetryer } from 'axios-retryer';
import { createTokenRefreshPlugin } from 'axios-retryer/plugins/TokenRefreshPlugin';
import { createCircuitBreaker } from 'axios-retryer/plugins/CircuitBreakerPlugin';
import { createMetricsPlugin } from 'axios-retryer/plugins/MetricsPlugin';
export const api = createRetryer({ retries: 3 })
.use(createTokenRefreshPlugin(async (axios) => {
const { data } = await axios.post('/auth/refresh');
return { token: data.accessToken };
}))
.use(createCircuitBreaker({ failureThreshold: 5, openTimeout: 30_000 }))
.use(createMetricsPlugin());
api.on('onTokenRefreshed', (token) => console.log(token));
api.on('onMetricsUpdated', (m) => console.log(m.successfulRetries)); customErrorDetector for GraphQL APIs that return errors in 200 bodies. You can resolve the refresh callback with no token to skip a cycle without failure events.- Access tokens expire and protected routes need silent replay after refresh
- Multiple concurrent requests can race on a 401
- Auth errors appear in 200 response bodies (GraphQL)
- A failing upstream should stop receiving requests while recovering
- You want to reduce latency during partial outages
- Downstream rate limits need enforced back-off at the client
- Repeated identical reads should be deduped or served from memory
- You want to reduce server load for stable read data
- Offline-first data should be available from a previous response
MANUAL mode) and lets you replay them on demand. Built-in idempotency safeguards, auth-request skipping, and age limits.- Offline-first SPA needs to queue requests while disconnected
- User should manually trigger retry after reviewing failures
- Failed mutations must survive a page reload
getMetrics() returns a zeroed snapshot.- You need real-time retry metrics for dashboards or alerting
onMetricsUpdatedevents are required in your monitoring pipeline
debug: true in non-prod environments.- Debug logs must not leak tokens, passwords, or PII
- Verbose logging is needed in staging but logs are shipped externally