Skip to content

Commit 2e4413b

Browse files
authored
adding explicit retry count logic (#119)
Added explicit retry count logic to prevent underlying & misleading exceptions. ### Testing Ran large PDFs via integration tests.
1 parent 51a54ff commit 2e4413b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/hooks/custom/SplitPdfHook.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export class SplitPdfHook
207207
// We need to hardcode them here until we're able to reuse the SDK
208208
// from within this hook
209209

210+
const allowedRetries = 3;
210211
const retryConfig = {
211212
strategy: "backoff",
212213
backoff: {
@@ -219,13 +220,19 @@ export class SplitPdfHook
219220

220221
const retryCodes = ["502", "503", "504"];
221222

223+
222224
this.partitionRequests[operationID] = async.parallelLimit(
223225
requests.map((req, pageIndex) => async () => {
224226
const pageNumber = pageIndex + startingPageNumber;
227+
let retryCount = 0;
225228
try {
226229
const response = await retry(
227230
async () => {
228-
return await this.client!.request(req);
231+
retryCount++;
232+
if (retryCount > allowedRetries) {
233+
throw new Error(`Number of retries exceeded for page ${pageNumber}`);
234+
}
235+
return await this.client!.request(req.clone());
229236
},
230237
{ config: retryConfig, statusCodes: retryCodes }
231238
);

src/hooks/custom/common.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export class HTTPClientExtension extends HTTPClient {
3232
}
3333

3434
override async request(request: Request): Promise<Response> {
35-
const clone = request.clone();
36-
if (clone.url === "https://no-op/") {
35+
if (request.url === "https://no-op/") {
3736
return new Response('{}', {
3837
headers: [
3938
["fake-response", "fake-response"]
@@ -42,6 +41,6 @@ export class HTTPClientExtension extends HTTPClient {
4241
statusText: 'OK_NO_OP'
4342
});
4443
}
45-
return super.request(clone);
44+
return super.request(request);
4645
}
4746
}

0 commit comments

Comments
 (0)