Skip to content

Commit

Permalink
fix(retry): retry on limits error (#90)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Pilar <[email protected]>
  • Loading branch information
pilartomas authored Mar 18, 2024
1 parent 297ecd2 commit 1038369
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import range from 'lodash/range.js';

import { Client } from '../../src/client.js';
import { HttpError } from '../../src/errors.js';
import {
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 1038369

Please sign in to comment.