diff --git a/src/hooks/custom/SplitPdfHook.ts b/src/hooks/custom/SplitPdfHook.ts index 3c288945..f6237836 100644 --- a/src/hooks/custom/SplitPdfHook.ts +++ b/src/hooks/custom/SplitPdfHook.ts @@ -207,6 +207,7 @@ export class SplitPdfHook // We need to hardcode them here until we're able to reuse the SDK // from within this hook + const allowedRetries = 3; const retryConfig = { strategy: "backoff", backoff: { @@ -219,13 +220,19 @@ export class SplitPdfHook const retryCodes = ["502", "503", "504"]; + this.partitionRequests[operationID] = async.parallelLimit( requests.map((req, pageIndex) => async () => { const pageNumber = pageIndex + startingPageNumber; + let retryCount = 0; try { const response = await retry( async () => { - return await this.client!.request(req); + retryCount++; + if (retryCount > allowedRetries) { + throw new Error(`Number of retries exceeded for page ${pageNumber}`); + } + return await this.client!.request(req.clone()); }, { config: retryConfig, statusCodes: retryCodes } ); diff --git a/src/hooks/custom/common.ts b/src/hooks/custom/common.ts index bec21cc0..005482aa 100644 --- a/src/hooks/custom/common.ts +++ b/src/hooks/custom/common.ts @@ -32,8 +32,7 @@ export class HTTPClientExtension extends HTTPClient { } override async request(request: Request): Promise { - const clone = request.clone(); - if (clone.url === "https://no-op/") { + if (request.url === "https://no-op/") { return new Response('{}', { headers: [ ["fake-response", "fake-response"] @@ -42,6 +41,6 @@ export class HTTPClientExtension extends HTTPClient { statusText: 'OK_NO_OP' }); } - return super.request(clone); + return super.request(request); } }