diff --git a/package.json b/package.json index e83e78c..cee7f03 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jupiterone/jupiterone-client-nodejs", - "version": "2.1.0", + "version": "2.1.1", "description": "A node.js client wrapper for JupiterOne public API", "repository": { "type": "git", diff --git a/src/index.ts b/src/index.ts index 1f62e2c..d9e2461 100644 --- a/src/index.ts +++ b/src/index.ts @@ -373,6 +373,7 @@ export class JupiterOneClient { let progress: any; do { + this.logger.debug({j1ql}, "Sending query"); const res = await this.graphClient.query({ query: QUERY_V1, variables: { @@ -389,6 +390,7 @@ export class JupiterOneClient { throw new Error(`JupiterOne returned error(s) for query: '${j1ql}'`); } + this.logger.debug(res.data, "Retrieved response"); const deferredUrl = res.data.queryV1.url; let status = JobStatus.IN_PROGRESS; let statusFile: any; @@ -400,7 +402,7 @@ export class JupiterOneClient { } seconds.`, ); } - this.logger.trace('Sleeping to wait for JobCompletion'); + this.logger.debug('Sleeping to wait for JobCompletion'); await sleep(100); statusFile = await networkRequest(deferredUrl); status = statusFile.status; @@ -411,6 +413,7 @@ export class JupiterOneClient { throw new Error(`JupiterOne returned error(s) for query: '${statusFile.error}'`); } + this.logger.info("Retrieving query data"); const result = statusFile.data; if (showProgress && !limitCheck) { diff --git a/src/networkRequest.ts b/src/networkRequest.ts index 3b4695c..1bf58db 100644 --- a/src/networkRequest.ts +++ b/src/networkRequest.ts @@ -1,20 +1,25 @@ // Temporary helper file because it's difficult to mock in the current architecture import fetch from 'node-fetch'; +import { retry } from "@lifeomic/attempt"; export const networkRequest = async ( url: string, ): Promise> => { - const result = await fetch(url); + const result = await retry(async () => { + console.log(`Fetching ${url}`); + const result = await fetch(url); + const { status } = result; - const { status, headers } = result; + if (status < 200 || status >= 300) { + const body = await result.text(); + throw new Error(`HTTP request failed (${status}): ${body}`); + } - if (status < 200 || status >= 300) { - const body = await result.text(); - throw new Error(`HTTP request failed (${status}): ${body}`); - } + return result; + }); - const contentType = headers.get('content-type'); + const contentType = result.headers.get('content-type'); if (contentType?.includes('application/json') === false) { const body = await result.text(); throw new Error(`HTTP response is not JSON but ${contentType}: ${body}`);