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

Aperta
#572 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@foxxx009 ci sta già lavorando.

Dal 28/9/2026.

  • #573 di @foxxx009 — aperta
  • #579 di @PINYOPATTANAWASANPORN — aperta
  • #586 di @Proxima84-code — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api

Direzione di ricerca

The 429 branch is in apiRequest() in src/lib/api.ts, where the Retry-After header is parsed with parseInt and the || fallback is dead. Two open pull requests (#573 and #586) already target this, so read them and the thread before starting. Done means HTTP-date and delay-seconds values both populate the wait message and ApiRequestError.retryAfter, the fallback message is reachable, and unit tests cover the four header cases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug enhancement good first issue

Problem

src/lib/api.ts → apiRequest(), from the rate-limit handling added in #44:

if (res.status === 429) {
  const retryAfter = res.headers.get("Retry-After");
  const seconds = retryAfter ? parseInt(retryAfter, 10) : NaN;
  const waitMsg = Number.isFinite(seconds)
    ? ` Please wait ${seconds} second${seconds === 1 ? "" : "s"} before trying again.`
    : "";
  throw new ApiRequestError(
    `You're doing that too fast.${waitMsg}` || `Rate limited. Please try again later.`,
    429,
    Number.isFinite(seconds) ? seconds : undefined,
  );
}
  1. HTTP-date Retry-After is dropped. RFC 9110 §10.2.3 allows Retry-After to be either delay-seconds or an HTTP-date, such as Retry-After: Wed, 21 Oct 2026 07:28:00 GMT, which proxies and CDNs commonly send. parseInt("Wed, 21 Oct…", 10) is NaN, so the wait time disappears from both the message and ApiRequestError.retryAfter. Callers that read retryAfter to throttle retries get undefined.
  2. The fallback message is unreachable. The left side of || is a template literal that always starts with "You're doing that too fast.", so it's always truthy. "Rate limited. Please try again later." can never be used, which suggests the intended "no wait info" message was lost.

Suggested fix

  • Parse both forms. Use the seconds if /^\d+$/ matches. Otherwise use Date.parse(value) and compute Math.max(0, Math.ceil((date - Date.now()) / 1000)).
  • Choose the message explicitly: the "wait N seconds" wording when seconds are known, and the plain fallback otherwise. Remove the dead ||.
  • Add unit tests for delay-seconds, an HTTP-date, a missing header and a garbage header value. lib/api.ts has limited coverage (#370).

Related: #44, #370.

Lingua principale
TypeScript
Stelle
1
Fork
94
Merge medio
1h 2m
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MergeFi/frontend

Tutte le issue di MergeFi/frontend

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.