From 1038369a0b5b3ee471823eeb05c5be72ca7aec89 Mon Sep 17 00:00:00 2001 From: Tomas Pilar Date: Mon, 18 Mar 2024 08:32:32 +0100 Subject: [PATCH] fix(retry): retry on limits error (#90) Signed-off-by: Tomas Pilar --- src/client.ts | 2 +- tests/e2e/client.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 2f45bc4..72d9b4f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -53,7 +53,7 @@ export class Client { const _client = createApiClient({ baseUrl: endpoint, headers, - fetch: fetchRetry(fetch) as any, // https://github.com/jonbern/fetch-retry/issues/89 + fetch: fetchRetry(fetch, { retryOn: [429] }), // Retry on network errors and when rate limits or concurrency limits (due to external factors) are hit }); const _streamingClient = createStreamingApiClient({ baseUrl: endpoint, diff --git a/tests/e2e/client.test.ts b/tests/e2e/client.test.ts index c1ce6d9..8427c75 100644 --- a/tests/e2e/client.test.ts +++ b/tests/e2e/client.test.ts @@ -1,3 +1,5 @@ +import range from 'lodash/range.js'; + import { Client } from '../../src/client.js'; import { HttpError } from '../../src/errors.js'; import { @@ -210,4 +212,13 @@ describe('client', () => { }).rejects.toHaveProperty('name', 'AbortError'); }); }); + + describe('limits', () => { + test('should handle rate limits', async () => { + const promise = Promise.all( + range(0, 100).map(() => client.tune.types({})), + ); + await expect(promise).toResolve(); + }); + }); });