Every retry library I found did the same thing: wrap a function, retry it a few times, throw if it still fails.
Fine until the retries run out and the error just... disappears into a catch block. No record of what request failed, what it was trying to send, or why. I'd find out a webhook silently dropped three days later when someone asked why an order never synced.
So I built smart-retry a small TypeScript retry library that does two things most others don't:
- Drop-in Axios and Fetch clients, not just a generic wrapper function
- Automatic failure logging when a request exhausts all retries, it gets written to disk with its URL, method, headers, body, and error, so you can inspect or replay it later instead of losing it the moment it throws
Quick look
import { createAxiosRetry } from '@aubaid/smart-retry';
const client = createAxiosRetry({
maxRetries: 5,
delay: 2000,
backoff: 'exponential',
});
const response = await client.get('https://api.example.com/users');
If that fails after 5 attempts, you don't just get a thrown error — you get a log:
const manager = client.getRetryManager();
const failed = await manager.getFailedRequests();
console.log(`${failed.length} requests logged`);
console.log('Log file:', manager.getLogFilePath());
It only retries things worth retrying by default network errors, timeouts, 429s, and 5xx and you can override that with a shouldRetry callback.
Where I need help
- defaultShouldRetry doesn't retry Axios timeout errors
- AxiosRetry has zero test coverage
- No maxDelay cap for exponential backoff (already has a PR in progress!)
- Reduce any usage in the public types
- README doesn't document log rotation config
All labeled good first issue. CONTRIBUTING.md has the dev setup if you want to jump in.
npm install @aubaid/smart-retry
Repo: https://github.com/AubaidFarrukh/smart-retry issues, PRs, and "this API is weird" feedback all welcome.
This article was originally published by DEV Community and written by Aubaid farroukh.
Read original article on DEV Community