You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HttpClient.withRateLimiter: let RateLimiterError be handled as an HttpClientError #10697
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:
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:
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.
Pass the request to the handlers of HttpClient.catchTag, HttpClient.catchTags and HttpClient.catch, for example as a second argument.
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.
Activity
Respect ORCID’s rate limits