I Built a Retry Library Because I Kept Losing Failed API Calls
说明与用途
smart-retry 自动重试 Axios/Fetch 请求,记录失败细节,便于后续分析或重放。
问题
Existing retry libraries only retry a function and throw on failure, leaving no record of the failed request, making debugging hard.
结果
The library provides automatic retries for network errors, timeouts, 429s, and 5xx responses, logs detailed failure information to disk, and exposes a manager to inspect and replay failed requests.
工作流
- 1. Install the library:
npm install @aubaid/smart-retry - 2. Create a retry-enabled client:
const client = createAxiosRetry({maxRetries:5, delay:2000, backoff:'exponential'}); - 3. Make API calls through the client (e.g.,
await client.get('https://api.example.com/users')). - 4. If retries exhaust, the library logs the failed request to a file.
- 5. Retrieve logged failures via
client.getRetryManager().getFailedRequests()and view log file path withgetLogFilePath().
证据
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
- 记录日期: 2026-09-06T09:06:42.668Z