fix(api): parse Retry-After HTTP-date format and remove dead fallback code (#572) - #579
Open
PINYOPATTANAWASANPORN wants to merge 2 commits into
Conversation
… 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.
|
@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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Fixed 429 rate-limit handling in
apiRequestby supporting RFC 9110 HTTP-date strings inRetry-Afterheaders and removing dead fallback code (#572).Root Cause / Technical Context
apiRequestpreviously usedparseInt(retryAfter, 10), which returnedNaNwhenRetry-Afterwas formatted as an HTTP-date string (e.g.Sun, 04 Oct 2026 21:40:00 GMT), causing the retry-after duration to be ignored.`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.parseRetryAfterhelper supporting integer seconds and RFC 9110 HTTP-date headers.api.test.tsvalidating 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