Skip to content

fix(api): parse Retry-After HTTP-date format and remove dead fallback code (#572) - #579

Open
PINYOPATTANAWASANPORN wants to merge 2 commits into
MergeFi:mainfrom
PINYOPATTANAWASANPORN:fix/apirequest-retry-after-http-date-572
Open

PINYOPATTANAWASANPORN wants to merge 2 commits into
MergeFi:mainfrom
PINYOPATTANAWASANPORN:fix/apirequest-retry-after-http-date-572

Conversation

@PINYOPATTANAWASANPORN

Copy link
Copy Markdown

Summary of Changes

Fixed 429 rate-limit handling in apiRequest by supporting RFC 9110 HTTP-date strings in Retry-After headers and removing dead fallback code (#572).

Root Cause / Technical Context

  1. apiRequest previously used parseInt(retryAfter, 10), which returned NaN when Retry-After was formatted as an HTTP-date string (e.g. Sun, 04 Oct 2026 21:40:00 GMT), causing the retry-after duration to be ignored.
  2. The template string `You're doing that too fast.${waitMsg}` is non-empty, rendering the right operand of || "Rate limited. Please try again later." completely unreachable dead code.
  3. Fix details:
    • Added parseRetryAfter helper supporting integer seconds and RFC 9110 HTTP-date headers.
    • Removed dead fallback OR expression.
    • Added unit test suite in api.test.ts validating integer seconds, HTTP-date parsing, and 429 error formatting.

Verification & Testing

Ran npx jest src/lib/api.test.ts --coverage=false:

PASS src/lib/api.test.ts
  fetchIndexableReputationHandles
    √ returns only profiles that explicitly opted in (4 ms)
    √ returns nothing when the backend omits the flag entirely (1 ms)
    √ drops entries with a blank username
    √ falls back to the caller's list when the backend is unreachable
  parseRetryAfter
    √ parses integer seconds correctly (2 ms)
    √ parses HTTP-date headers into remaining seconds (1 ms)
  apiRequest rate limiting (429)
    √ formats 429 error message correctly with integer Retry-After (8 ms)
    √ formats 429 error message correctly without Retry-After header

Test Suites: 1 passed, 1 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        1.389 s

… code (MergeFi#572)

Add parseRetryAfter helper to compute seconds from both integer seconds and HTTP-date strings per RFC 9110, and clean up dead-code fallback expression.
… code (MergeFi#572)

Add parseRetryAfter helper to compute seconds from both integer seconds and HTTP-date strings per RFC 9110, and clean up dead-code fallback expression.
@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@PINYOPATTANAWASANPORN 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.

1 participant