Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sdk/createConductorClient/helpers/fetchWithRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export const retryFetch = async (
retries = 5,
delay = 1000
): Promise<Response> => {
const response = await fetchFn(input, init);
// Clone the Request object if input is a Request, so retries work correctly.
// Request objects can only be used once - attempting to reuse them throws:
// "Cannot construct a Request with a Request object that has already been used"
const requestInput = input instanceof Request ? input.clone() : input;

const response = await fetchFn(requestInput, init);
if (response.status == 429 && retries > 0) {
await new Promise((resolve) => setTimeout(resolve, delay));
return retryFetch(input, init, fetchFn, retries - 1, delay * 2);
Expand Down
Loading