Skip to content

Commit beaffa7

Browse files
committed
Add retry for status URL check
This can help work around issues with CloudFront connections. EU environment sees these from time to time.
1 parent 5168178 commit beaffa7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export class JupiterOneClient {
373373
let progress: any;
374374

375375
do {
376+
this.logger.debug({j1ql}, "Sending query");
376377
const res = await this.graphClient.query({
377378
query: QUERY_V1,
378379
variables: {
@@ -389,6 +390,7 @@ export class JupiterOneClient {
389390
throw new Error(`JupiterOne returned error(s) for query: '${j1ql}'`);
390391
}
391392

393+
this.logger.debug(res.data, "Retrieved response");
392394
const deferredUrl = res.data.queryV1.url;
393395
let status = JobStatus.IN_PROGRESS;
394396
let statusFile: any;
@@ -400,7 +402,7 @@ export class JupiterOneClient {
400402
} seconds.`,
401403
);
402404
}
403-
this.logger.trace('Sleeping to wait for JobCompletion');
405+
this.logger.debug('Sleeping to wait for JobCompletion');
404406
await sleep(100);
405407
statusFile = await networkRequest(deferredUrl);
406408
status = statusFile.status;
@@ -411,6 +413,7 @@ export class JupiterOneClient {
411413
throw new Error(`JupiterOne returned error(s) for query: '${statusFile.error}'`);
412414
}
413415

416+
this.logger.info("Retrieving query data");
414417
const result = statusFile.data;
415418

416419
if (showProgress && !limitCheck) {

src/networkRequest.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
// Temporary helper file because it's difficult to mock in the current architecture
22

33
import fetch from 'node-fetch';
4+
import { retry } from "@lifeomic/attempt";
45

56
export const networkRequest = async (
67
url: string,
78
): Promise<Record<string, unknown>> => {
8-
const result = await fetch(url);
9+
const result = await retry(async () => {
10+
console.log(`Fetching ${url}`);
11+
const result = await fetch(url);
12+
const { status } = result;
913

10-
const { status, headers } = result;
14+
if (status < 200 || status >= 300) {
15+
const body = await result.text();
16+
throw new Error(`HTTP request failed (${status}): ${body}`);
17+
}
1118

12-
if (status < 200 || status >= 300) {
13-
const body = await result.text();
14-
throw new Error(`HTTP request failed (${status}): ${body}`);
15-
}
19+
return result;
20+
});
1621

17-
const contentType = headers.get('content-type');
22+
const contentType = result.headers.get('content-type');
1823
if (contentType?.includes('application/json') === false) {
1924
const body = await result.text();
2025
throw new Error(`HTTP response is not JSON but ${contentType}: ${body}`);

0 commit comments

Comments
 (0)