Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/hooks/custom/SplitPdfHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 }
);
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/custom/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export class HTTPClientExtension extends HTTPClient {
}

override async request(request: Request): Promise<Response> {
const clone = request.clone();
if (clone.url === "https://no-op/") {
if (request.url === "https://no-op/") {
return new Response('{}', {
headers: [
["fake-response", "fake-response"]
Expand All @@ -42,6 +41,6 @@ export class HTTPClientExtension extends HTTPClient {
statusText: 'OK_NO_OP'
});
}
return super.request(clone);
return super.request(request);
}
}
Loading