Skip to content

feat: auto retry rate limit#53

Merged
FreekBes merged 2 commits into
mainfrom
feat/auto-retry-rate-limit
Jun 24, 2026
Merged

feat: auto retry rate limit#53
FreekBes merged 2 commits into
mainfrom
feat/auto-retry-rate-limit

Conversation

@FreekBes

Copy link
Copy Markdown
Member

Added retry logic that automatically requeues requests when they return a 429 or 5xx error.

  • 429 (rate limit): retried indefinitely, waiting for the duration of the Retry-After header (or retryAfterFallback seconds when it is absent). Applies to every request, including writes — a 429 is rejected before processing, so it is always safe to retry.
  • 5xx (server error): retried up to maxServerErrorRetries times (default 5), waiting serverErrorBackoff ms between attempts. Only GET requests are retried on 5xx, since writes (post/put/patch/delete) may not be idempotent. After the retries are exhausted the last Response is returned, so existing .ok/.status checks keep working.

Added more config for this:

interface RetryConfig {
    enabled?: boolean; // master switch, default is true
    maxServerErrorRetries?: number; // max retries on 5xx errors per request, default is 5. 429s are always retried indefinitely.
    serverErrorBackoff?: number; // base ms to wait before retrying a 5xx error, default is 30000
    retryAfterFallback?: number; // seconds to wait on a 429 when no Retry-After header is present, default is 1
    jitter?: number; // max random extra ms added to every retry wait, default is 10000
}

FreekBes and others added 2 commits June 24, 2026 16:15
Bake rate-limit (429) and server-error (5xx) retry/back-off into the
request layer so callers no longer need their own retry loops.

- 429s are retried indefinitely, respecting the Retry-After header
  (falling back to retryAfterFallback seconds when absent). Applies to
  all methods, since a 429 is rejected before processing.
- 5xx errors are retried up to maxServerErrorRetries times (default 5)
  for GET only, since writes may not be idempotent. The last Response is
  returned once retries are exhausted, keeping the existing return
  contract intact.
- Every retry is re-scheduled through the limiter, with random jitter
  added to each wait.
- Configurable (and disablable) via the new `retry` setting.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The library now retries rate-limited requests automatically, so the
manual getPage-based retry in the example is no longer needed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@FreekBes FreekBes requested a review from Copilot June 24, 2026 17:05
@FreekBes FreekBes added the enhancement New feature or request label Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automatic retry behavior to Fast42 API requests, integrating rate-limit (429) and server-error (5xx) retries into the internal request scheduling so callers can keep using the existing Response contract.

Changes:

  • Introduces retry configuration (RetryConfig) with defaults and a master enable/disable switch.
  • Wraps internal request scheduling with scheduleWithRetry to transparently retry 429s (indefinitely) and GET 5xx responses (bounded).
  • Adds Jest coverage for the retry behavior and documents configuration/behavior in the README.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/index.ts Adds retry config defaults and implements scheduleWithRetry used by GET and write requests.
tests/index.test.ts Adds unit tests validating 429 and 5xx retry behavior and default retry settings.
README.md Documents the new retry feature and configuration and removes now-unneeded manual 429 retry example logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.ts
@FreekBes FreekBes merged commit fb335c6 into main Jun 24, 2026
2 checks passed
@FreekBes FreekBes deleted the feat/auto-retry-rate-limit branch June 24, 2026 17:18
github-actions Bot pushed a commit that referenced this pull request Jun 24, 2026
# [3.0.0](v2.2.0...v3.0.0) (2026-06-24)

### Features

* auto retry rate limit ([#53](#53)) ([fb335c6](fb335c6))
* use native fetch instead of node-fetch ([a878ea2](a878ea2))

### BREAKING CHANGES

* node-fetch has been removed. Consumers must run on Node.js 18 or newer, and the exported Response type is now the native (undici) Response rather than node-fetch's. The methods this library uses are identical, but code relying on node-fetch-specific Response behavior (e.g. body as a Node stream) may need adjusting.
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants