Skip to content

fix(api): parse HTTP-date Retry-After and drop dead fallback in 429 handler (#572) - #573

Open
foxxx009 wants to merge 1 commit into
MergeFi:mainfrom
foxxx009:fix/572-api-429-retry-after
Open

foxxx009 wants to merge 1 commit into
MergeFi:mainfrom
foxxx009:fix/572-api-429-retry-after

Conversation

@foxxx009

Copy link
Copy Markdown

Fixes #572.

What's wrong

apiRequest's 429 handler parses Retry-After with parseInt(), which only understands the delay-seconds form. Per RFC 9110 the header may also be an HTTP-date (Retry-After: Wed, 21 Oct 2026 07:28:00 GMT); with that form parseInt yields NaN, so retryAfter surfaced to callers is undefined and they can't honour the backoff.

The error message also has a dead fallback: `You're doing that too fast.${waitMsg}` || `Rate limited...` — the left operand is a template literal and always truthy, so the second branch never runs.

What changed

  • parseRetryAfter() now accepts both RFC 9110 forms: delay-seconds (/^\d+$/) and HTTP-date (Date.parse → Math.max(0, ceil((date - now)/1000))). Garbage values still yield undefined.
  • Dropped the dead || fallback and made the two messages explicit: with wait info vs. without.
  • Added unit tests covering delay-seconds, HTTP-date, missing header, and garbage header.

Verification

  • jest src/lib/api.test.ts — 10/10 pass (4 new).
  • Full suite: same results as main (the 3 pre-existing failing suites are untouched by this change).
  • eslint src/lib/api.ts src/lib/api.test.ts — clean.

…andler (MergeFi#572)

- Parse Retry-After as delay-seconds OR an RFC 9110 HTTP-date; previously
  parseInt() dropped the date form so callers reading retryAfter got undefined.
- Remove the dead `|| 'Rate limited...'` fallback (the left operand is always
  truthy), restoring the intended 'no wait info' message.
- Add unit tests for delay-seconds, HTTP-date, missing, and garbage headers.

Fixes MergeFi#572
@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

@foxxx009 is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apiRequest's 429 handling ignores Retry-After in HTTP-date form, and its || "Rate limited..." fallback message is dead code

1 participant