`HttpClient.withRateLimiter`: let `RateLimiterError` be handled as an `HttpClientError`

Aperta
#10,697 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@effect-bot ci sta già lavorando.

Dal 17/11/2026.

  • #10713 di @effect-bot — integrata

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement
What is the problem this feature would solve?

HttpClient.withRateLimiter adds RateLimiter.RateLimiterError to the client's error type, so the result isn't a plain HttpClient any more. To provide it as HttpClient.HttpClient again, the error has to be removed:

httpClient.pipe(
  HttpClient.withRateLimiter({
    limiter,
    key: 'orcid',
    algorithm: 'token-bucket',
    limit: 24,
    window: '1 second',
  }),
  HttpClient.catchTag('RateLimiterError', Effect.die),
)

The natural thing would be to turn it into an HttpClientError with a TransportError reason, so callers handle a failing limiter store (such as Redis being unavailable) like any other failed request. But TransportError needs the request, and HttpClient.catchTag's handler only receives the error, so dying is the only option.

HttpClient.transform does receive the request, but it only changes the response side. The RateLimiterError stays in the client's preprocess type, so the result still isn't assignable to HttpClient.

We're working around it by calling RateLimiter.sleep inside HttpClient.transform ourselves. That loses withRateLimiter's 429 retries and its handling of rate-limit headers.

What is the feature you are proposing to solve the problem?

Any of these would work:

  1. An option on withRateLimiter to fail with an HttpClientError (TransportError, with the RateLimiterError as its cause) instead of a RateLimiterError, so the result is a plain HttpClient.
  2. Pass the request to the handlers of HttpClient.catchTag, HttpClient.catchTags and HttpClient.catch, for example as a second argument.
  3. Make HttpClient.transform (or a variant of it) able to handle errors from the whole client, not just the response.

Option 1 fits best for HTTP clients. Option 2 would help with other errors added by client combinators too.

What alternatives have you considered?
  • HttpClient.catchTag('RateLimiterError', Effect.die): fine with RateLimiter.layerStoreMemory, which can't fail, but a store failure with layerStoreRedis becomes a defect.
  • RateLimiter.sleep inside HttpClient.transform, mapping the error with the request: works, but reimplements part of withRateLimiter and loses its 429 and header handling.

Version: effect 4.1.2

Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
20h 31m
PR unite (30g)
733

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.