diff --git a/dist/index.js b/dist/index.js index 709249cc..37a04a94 100644 --- a/dist/index.js +++ b/dist/index.js @@ -71,14 +71,19 @@ exports.ticsConfig = { tmpDir: (0, core_1.getInput)('tmpDir'), trustStrategy: (0, core_1.getInput)('trustStrategy'), secretsFilter: getSecretsFilter((0, core_1.getInput)('secretsFilter')), - viewerUrl: (0, core_1.getInput)('viewerUrl') + viewerUrl: (0, core_1.getInput)('viewerUrl'), + retries: 10 }; const ignoreSslError = exports.ticsConfig.hostnameVerification === '0' || exports.ticsConfig.hostnameVerification === 'false' || exports.ticsConfig.trustStrategy === 'self-signed' || exports.ticsConfig.trustStrategy === 'all'; -exports.octokit = (0, github_1.getOctokit)(exports.ticsConfig.githubToken, { request: { retries: 10 } }, (__nccwpck_require__(6298).retry)); -exports.httpClient = new http_client_1.HttpClient('tics-github-action', undefined, { allowRetries: true, maxRetries: 10, ignoreSslError: ignoreSslError }); +exports.octokit = (0, github_1.getOctokit)(exports.ticsConfig.githubToken, { request: { retries: exports.ticsConfig.retries, retryAfter: 5 } }, (__nccwpck_require__(6298).retry)); +exports.httpClient = new http_client_1.HttpClient('tics-github-action', undefined, { + allowRetries: true, + maxRetries: exports.ticsConfig.retries, + ignoreSslError: ignoreSslError +}); exports.baseUrl = (0, api_helper_1.getTicsWebBaseUrlFromUrl)(exports.ticsConfig.ticsConfiguration); exports.viewerUrl = exports.ticsConfig.viewerUrl ? exports.ticsConfig.viewerUrl.replace(/\/+$/, '') : exports.baseUrl; @@ -94,6 +99,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.deletePreviousReviewComments = exports.postAnnotations = exports.getPostedReviewComments = void 0; const logger_1 = __nccwpck_require__(6440); const configuration_1 = __nccwpck_require__(5527); +const error_1 = __nccwpck_require__(5922); /** * Gets a list of all reviews posted on the pull request. * @returns List of reviews posted on the pull request. @@ -110,9 +116,7 @@ async function getPostedReviewComments() { response = await configuration_1.octokit.paginate(configuration_1.octokit.rest.pulls.listReviewComments, params); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Could not retrieve the review comments: ${message}`); } return response; @@ -156,9 +160,7 @@ function deletePreviousReviewComments(postedReviewComments) { await configuration_1.octokit.rest.pulls.deleteReviewComment(params); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Could not delete review comment: ${message}`); } } @@ -183,6 +185,7 @@ const artifact_1 = __nccwpck_require__(2605); const logger_1 = __nccwpck_require__(6440); const fs_1 = __nccwpck_require__(7147); const canonical_path_1 = __nccwpck_require__(5806); +const error_1 = __nccwpck_require__(5922); async function uploadArtifact() { const artifactClient = (0, artifact_1.create)(); try { @@ -195,9 +198,7 @@ async function uploadArtifact() { } } catch (error) { - let message = 'reason unknown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.debug('Failed to upload artifact: ' + message); } } @@ -249,6 +250,7 @@ const configuration_1 = __nccwpck_require__(5527); const summary_1 = __nccwpck_require__(1502); const markdown_1 = __nccwpck_require__(5300); const enums_1 = __nccwpck_require__(1655); +const error_1 = __nccwpck_require__(5922); /** * Gets a list of all comments on the pull request. * @returns List of comments on the pull request. @@ -265,9 +267,7 @@ async function getPostedComments() { response = await configuration_1.octokit.paginate(configuration_1.octokit.rest.issues.listComments, params); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Could not retrieve the comments: ${message}`); } return response; @@ -308,9 +308,7 @@ async function postComment(body) { logger_1.logger.info('Posted comment for this pull request.'); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Posting the comment failed: ${message}`); } } @@ -328,9 +326,7 @@ function deletePreviousComments(comments) { await configuration_1.octokit.rest.issues.deleteComment(params); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Removing a comment failed: ${message}`); } } @@ -363,6 +359,7 @@ exports.getChangedFilesOfCommit = void 0; const canonical_path_1 = __nccwpck_require__(5806); const logger_1 = __nccwpck_require__(6440); const configuration_1 = __nccwpck_require__(5527); +const error_1 = __nccwpck_require__(5922); /** * Sends a request to retrieve the changed files for a given pull request to the GitHub API. * @returns List of changed files within the GitHub Pull request. @@ -400,9 +397,7 @@ async function getChangedFilesOfCommit() { logger_1.logger.info('Retrieved changed files from commit.'); } catch (error) { - let message = 'error unknown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.exit(`Could not retrieve the changed files: ${message}`); } return response; @@ -423,6 +418,7 @@ const fs_1 = __nccwpck_require__(7147); const canonical_path_1 = __nccwpck_require__(5806); const logger_1 = __nccwpck_require__(6440); const configuration_1 = __nccwpck_require__(5527); +const error_1 = __nccwpck_require__(5922); /** * Sends a request to retrieve the changed files for a given pull request to the GitHub API. * @returns List of changed files within the GitHub Pull request. @@ -458,9 +454,7 @@ async function getChangedFilesOfPullRequest() { logger_1.logger.info('Retrieved changed files from pull request.'); } catch (error) { - let message = 'error unknown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.exit(`Could not retrieve the changed files: ${message}`); } return response; @@ -498,6 +492,7 @@ const logger_1 = __nccwpck_require__(6440); const configuration_1 = __nccwpck_require__(5527); const enums_1 = __nccwpck_require__(1655); const markdown_1 = __nccwpck_require__(5300); +const error_1 = __nccwpck_require__(5922); /** * Create review on the pull request from the analysis given. * @param body Body containing the summary of the review @@ -517,9 +512,7 @@ async function postReview(body, event) { logger_1.logger.info('Posted review for this pull request.'); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Posting the review failed: ${message}`); } } @@ -543,9 +536,7 @@ async function postNothingAnalyzedReview(message) { logger_1.logger.info('Posted review for this pull request.'); } catch (error) { - let message = 'reason unkown'; - if (error instanceof Error) - message = error.message; + const message = (0, error_1.handleOctokitError)(error); logger_1.logger.error(`Posting the review failed: ${message}`); } } @@ -576,6 +567,30 @@ var Events; })(Events || (exports.Events = Events = {})); +/***/ }), + +/***/ 5922: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.handleOctokitError = void 0; +function handleOctokitError(error) { + let message = 'reason unkown'; + if (error instanceof Error) { + message = ''; + const retryCount = error.request?.request?.retryCount; + if (retryCount) { + message = `Retried ${retryCount} time(s), but got: `; + } + message += error.message; + } + return message; +} +exports.handleOctokitError = handleOctokitError; + + /***/ }), /***/ 6440: @@ -1210,6 +1225,7 @@ async function httpRequest(url) { headers.Authorization = `Basic ${configuration_1.ticsConfig.ticsAuthToken}`; } const response = await configuration_1.httpClient.get(url, headers); + const errorMessage = `Retried ${configuration_1.ticsConfig.retries} time(s), but got: HTTP request failed with status ${response.message.statusCode}.`; switch (response.message.statusCode) { case 200: const text = await response.readBody(); @@ -1221,24 +1237,22 @@ async function httpRequest(url) { } break; case 302: - logger_1.logger.exit(`HTTP request failed with status ${response.message.statusCode}. Please check if the given ticsConfiguration is correct (possibly http instead of https).`); + logger_1.logger.exit(`${errorMessage} Please check if the given ticsConfiguration is correct (possibly http instead of https).`); break; case 400: - const body = await response.readBody(); - console.log(body); - logger_1.logger.exit(`HTTP request failed with status ${response.message.statusCode}. ${JSON.parse(body).alertMessages[0].header}`); + logger_1.logger.exit(`${errorMessage} ${JSON.parse(await response.readBody()).alertMessages[0].header}`); break; case 401: - logger_1.logger.exit(`HTTP request failed with status ${response.message.statusCode}. Please provide a valid TICSAUTHTOKEN in your configuration. Check ${configuration_1.viewerUrl}/Administration.html#page=authToken`); + logger_1.logger.exit(`${errorMessage} Please provide a valid TICSAUTHTOKEN in your configuration. Check ${configuration_1.viewerUrl}/Administration.html#page=authToken`); break; case 403: - logger_1.logger.exit(`HTTP request failed with status ${response.message.statusCode}. Forbidden call: ${url}`); + logger_1.logger.exit(`${errorMessage} Forbidden call: ${url}`); break; case 404: - logger_1.logger.exit(`HTTP request failed with status ${response.message.statusCode}. Please check if the given ticsConfiguration is correct.`); + logger_1.logger.exit(`${errorMessage} Please check if the given ticsConfiguration is correct.`); break; default: - logger_1.logger.exit(`HTTP request failed with status ${response.message.statusCode}. Please check if your configuration is correct.`); + logger_1.logger.exit(`${errorMessage} ${response.message.statusMessage}`); break; } return; diff --git a/package-lock.json b/package-lock.json index 5caf9bd1..9df2fd86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@actions/github": "^5.1.1", "@actions/http-client": "^2.1.1", "@octokit/plugin-retry": "^6.0.1", + "@octokit/request-error": "^5.0.1", "canonical-path": "^1.0.0", "compare-versions": "^6.1.0", "semver": "^7.5.4", diff --git a/package.json b/package.json index 450011d2..3fc55a09 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@actions/github": "^5.1.1", "@actions/http-client": "^2.1.1", "@octokit/plugin-retry": "^6.0.1", + "@octokit/request-error": "^5.0.1", "canonical-path": "^1.0.0", "compare-versions": "^6.1.0", "semver": "^7.5.4", diff --git a/src/configuration.ts b/src/configuration.ts index 57389f3a..98188445 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -64,7 +64,8 @@ export const ticsConfig = { tmpDir: getInput('tmpDir'), trustStrategy: getInput('trustStrategy'), secretsFilter: getSecretsFilter(getInput('secretsFilter')), - viewerUrl: getInput('viewerUrl') + viewerUrl: getInput('viewerUrl'), + retries: 10 }; const ignoreSslError: boolean = @@ -73,7 +74,15 @@ const ignoreSslError: boolean = ticsConfig.trustStrategy === 'self-signed' || ticsConfig.trustStrategy === 'all'; -export const octokit = getOctokit(ticsConfig.githubToken, { request: { retries: 10 } }, require('@octokit/plugin-retry').retry); -export const httpClient = new HttpClient('tics-github-action', undefined, { allowRetries: true, maxRetries: 10, ignoreSslError: ignoreSslError }); +export const octokit = getOctokit( + ticsConfig.githubToken, + { request: { retries: ticsConfig.retries, retryAfter: 5 } }, + require('@octokit/plugin-retry').retry +); +export const httpClient = new HttpClient('tics-github-action', undefined, { + allowRetries: true, + maxRetries: ticsConfig.retries, + ignoreSslError: ignoreSslError +}); export const baseUrl = getTicsWebBaseUrlFromUrl(ticsConfig.ticsConfiguration); export const viewerUrl = ticsConfig.viewerUrl ? ticsConfig.viewerUrl.replace(/\/+$/, '') : baseUrl; diff --git a/src/github/annotations.ts b/src/github/annotations.ts index f2501c1a..bb4ffce2 100644 --- a/src/github/annotations.ts +++ b/src/github/annotations.ts @@ -2,6 +2,7 @@ import { logger } from '../helper/logger'; import { githubConfig, octokit } from '../configuration'; import { ReviewComment } from './interfaces'; import { AnalysisResults, TicsReviewComment } from '../helper/interfaces'; +import { handleOctokitError } from '../helper/error'; /** * Gets a list of all reviews posted on the pull request. @@ -18,8 +19,7 @@ export async function getPostedReviewComments(): Promise { }; response = await octokit.paginate(octokit.rest.pulls.listReviewComments, params); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Could not retrieve the review comments: ${message}`); } return response; @@ -65,8 +65,7 @@ export function deletePreviousReviewComments(postedReviewComments: ReviewComment }; await octokit.rest.pulls.deleteReviewComment(params); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Could not delete review comment: ${message}`); } } diff --git a/src/github/artifacts.ts b/src/github/artifacts.ts index 7a608f63..ce49cfa7 100644 --- a/src/github/artifacts.ts +++ b/src/github/artifacts.ts @@ -4,6 +4,7 @@ import { create } from '@actions/artifact'; import { logger } from '../helper/logger'; import { readdirSync } from 'fs'; import { join } from 'canonical-path'; +import { handleOctokitError } from '../helper/error'; export async function uploadArtifact(): Promise { const artifactClient = create(); @@ -18,8 +19,7 @@ export async function uploadArtifact(): Promise { logger.debug(`Failed to upload file(s): ${response.failedItems.join(', ')}`); } } catch (error: unknown) { - let message = 'reason unknown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.debug('Failed to upload artifact: ' + message); } } diff --git a/src/github/comments.ts b/src/github/comments.ts index bd34cb66..87da8254 100644 --- a/src/github/comments.ts +++ b/src/github/comments.ts @@ -5,6 +5,7 @@ import { createErrorSummary } from '../helper/summary'; import { generateStatusMarkdown } from '../helper/markdown'; import { Status } from '../helper/enums'; import { Comment } from './interfaces'; +import { handleOctokitError } from '../helper/error'; /** * Gets a list of all comments on the pull request. @@ -21,8 +22,7 @@ export async function getPostedComments(): Promise { }; response = await octokit.paginate(octokit.rest.issues.listComments, params); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Could not retrieve the comments: ${message}`); } return response; @@ -65,8 +65,7 @@ export async function postComment(body: string): Promise { await octokit.rest.issues.createComment(params); logger.info('Posted comment for this pull request.'); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Posting the comment failed: ${message}`); } } @@ -83,8 +82,7 @@ export function deletePreviousComments(comments: Comment[]): void { }; await octokit.rest.issues.deleteComment(params); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Removing a comment failed: ${message}`); } } diff --git a/src/github/commits.ts b/src/github/commits.ts index 640f05a7..c8a58e36 100644 --- a/src/github/commits.ts +++ b/src/github/commits.ts @@ -2,6 +2,7 @@ import { normalize } from 'canonical-path'; import { logger } from '../helper/logger'; import { githubConfig, octokit, ticsConfig } from '../configuration'; import { ChangedFile } from './interfaces'; +import { handleOctokitError } from '../helper/error'; /** * Sends a request to retrieve the changed files for a given pull request to the GitHub API. @@ -39,8 +40,7 @@ export async function getChangedFilesOfCommit(): Promise { }); logger.info('Retrieved changed files from commit.'); } catch (error: unknown) { - let message = 'error unknown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.exit(`Could not retrieve the changed files: ${message}`); } return response; diff --git a/src/github/pulls.ts b/src/github/pulls.ts index 1e12888a..6fdac116 100644 --- a/src/github/pulls.ts +++ b/src/github/pulls.ts @@ -3,6 +3,7 @@ import { normalize, resolve } from 'canonical-path'; import { logger } from '../helper/logger'; import { githubConfig, octokit, ticsConfig } from '../configuration'; import { ChangedFile } from './interfaces'; +import { handleOctokitError } from '../helper/error'; /** * Sends a request to retrieve the changed files for a given pull request to the GitHub API. @@ -39,8 +40,7 @@ export async function getChangedFilesOfPullRequest(): Promise { }); logger.info('Retrieved changed files from pull request.'); } catch (error: unknown) { - let message = 'error unknown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.exit(`Could not retrieve the changed files: ${message}`); } return response; diff --git a/src/github/review.ts b/src/github/review.ts index 31984791..cfc79c51 100644 --- a/src/github/review.ts +++ b/src/github/review.ts @@ -2,6 +2,7 @@ import { logger } from '../helper/logger'; import { githubConfig, octokit } from '../configuration'; import { Events, Status } from '../helper/enums'; import { generateStatusMarkdown } from '../helper/markdown'; +import { handleOctokitError } from '../helper/error'; /** * Create review on the pull request from the analysis given. @@ -22,8 +23,7 @@ export async function postReview(body: string, event: Events): Promise { await octokit.rest.pulls.createReview(params); logger.info('Posted review for this pull request.'); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Posting the review failed: ${message}`); } } @@ -48,8 +48,7 @@ export async function postNothingAnalyzedReview(message: string): Promise await octokit.rest.pulls.createReview(params); logger.info('Posted review for this pull request.'); } catch (error: unknown) { - let message = 'reason unkown'; - if (error instanceof Error) message = error.message; + const message = handleOctokitError(error); logger.error(`Posting the review failed: ${message}`); } } diff --git a/src/helper/error.ts b/src/helper/error.ts new file mode 100644 index 00000000..84428088 --- /dev/null +++ b/src/helper/error.ts @@ -0,0 +1,14 @@ +import { RequestError } from '@octokit/request-error'; + +export function handleOctokitError(error: unknown): string { + let message = 'reason unkown'; + if (error instanceof Error) { + message = ''; + const retryCount = (error as RequestError).request?.request?.retryCount; + if (retryCount) { + message = `Retried ${retryCount} time(s), but got: `; + } + message += error.message; + } + return message; +} diff --git a/src/tics/api_helper.ts b/src/tics/api_helper.ts index 6dd35f69..95244f7b 100644 --- a/src/tics/api_helper.ts +++ b/src/tics/api_helper.ts @@ -19,6 +19,8 @@ export async function httpRequest(url: string): Promise { const response: HttpClientResponse = await httpClient.get(url, headers); + const errorMessage = `Retried ${ticsConfig.retries} time(s), but got: HTTP request failed with status ${response.message.statusCode}.`; + switch (response.message.statusCode) { case 200: const text = await response.readBody(); @@ -29,28 +31,24 @@ export async function httpRequest(url: string): Promise { } break; case 302: - logger.exit( - `HTTP request failed with status ${response.message.statusCode}. Please check if the given ticsConfiguration is correct (possibly http instead of https).` - ); + logger.exit(`${errorMessage} Please check if the given ticsConfiguration is correct (possibly http instead of https).`); break; case 400: - const body = await response.readBody(); - console.log(body); - logger.exit(`HTTP request failed with status ${response.message.statusCode}. ${(JSON.parse(body)).alertMessages[0].header}`); + logger.exit(`${errorMessage} ${(JSON.parse(await response.readBody())).alertMessages[0].header}`); break; case 401: logger.exit( - `HTTP request failed with status ${response.message.statusCode}. Please provide a valid TICSAUTHTOKEN in your configuration. Check ${viewerUrl}/Administration.html#page=authToken` + `${errorMessage} Please provide a valid TICSAUTHTOKEN in your configuration. Check ${viewerUrl}/Administration.html#page=authToken` ); break; case 403: - logger.exit(`HTTP request failed with status ${response.message.statusCode}. Forbidden call: ${url}`); + logger.exit(`${errorMessage} Forbidden call: ${url}`); break; case 404: - logger.exit(`HTTP request failed with status ${response.message.statusCode}. Please check if the given ticsConfiguration is correct.`); + logger.exit(`${errorMessage} Please check if the given ticsConfiguration is correct.`); break; default: - logger.exit(`HTTP request failed with status ${response.message.statusCode}. Please check if your configuration is correct.`); + logger.exit(`${errorMessage} ${response.message.statusMessage}`); break; } return; diff --git a/test/tics/api_helper.test.ts b/test/tics/api_helper.test.ts index f4af4875..bff225ba 100644 --- a/test/tics/api_helper.test.ts +++ b/test/tics/api_helper.test.ts @@ -32,7 +32,7 @@ describe('httpRequest', () => { const response = await httpRequest('url'); const calledWith = - 'HTTP request failed with status 302. Please check if the given ticsConfiguration is correct (possibly http instead of https).'; + 'Retried undefined time(s), but got: HTTP request failed with status 302. Please check if the given ticsConfiguration is correct (possibly http instead of https).'; expect(response).toEqual(undefined); expect(exit).toHaveBeenCalledTimes(1); @@ -46,7 +46,7 @@ describe('httpRequest', () => { const exit = jest.spyOn(logger, 'exit'); const response = await httpRequest('url'); - const calledWith = 'HTTP request failed with status 400. header'; + const calledWith = 'Retried undefined time(s), but got: HTTP request failed with status 400. header'; expect(response).toEqual(undefined); expect(exit).toHaveBeenCalledTimes(1); @@ -59,7 +59,7 @@ describe('httpRequest', () => { const response = await httpRequest('url'); const calledWith = - 'HTTP request failed with status 401. Please provide a valid TICSAUTHTOKEN in your configuration. Check /Administration.html#page=authToken'; + 'Retried undefined time(s), but got: HTTP request failed with status 401. Please provide a valid TICSAUTHTOKEN in your configuration. Check /Administration.html#page=authToken'; expect(response).toEqual(undefined); expect(exit).toHaveBeenCalledTimes(1); @@ -71,7 +71,7 @@ describe('httpRequest', () => { const exit = jest.spyOn(logger, 'exit'); const response = await httpRequest('url'); - const calledWith = 'HTTP request failed with status 403. Forbidden call: url'; + const calledWith = 'Retried undefined time(s), but got: HTTP request failed with status 403. Forbidden call: url'; expect(response).toEqual(undefined); expect(exit).toHaveBeenCalledTimes(1); @@ -83,7 +83,8 @@ describe('httpRequest', () => { const exit = jest.spyOn(logger, 'exit'); const response = await httpRequest('url'); - const calledWith = 'HTTP request failed with status 404. Please check if the given ticsConfiguration is correct.'; + const calledWith = + 'Retried undefined time(s), but got: HTTP request failed with status 404. Please check if the given ticsConfiguration is correct.'; expect(response).toEqual(undefined); expect(exit).toHaveBeenCalledTimes(1); @@ -91,11 +92,13 @@ describe('httpRequest', () => { }); test('Should return undefined response and call exit on status null', async () => { - (httpClient.get as any).mockImplementationOnce((): Promise => Promise.resolve({ message: { statusCode: null } })); + (httpClient.get as any).mockImplementationOnce( + (): Promise => Promise.resolve({ message: { statusCode: null, statusMessage: 'Just because' } }) + ); const exit = jest.spyOn(logger, 'exit'); const response = await httpRequest('url'); - const calledWith = 'HTTP request failed with status null. Please check if your configuration is correct.'; + const calledWith = 'Retried undefined time(s), but got: HTTP request failed with status null. Just because'; expect(response).toEqual(undefined); expect(exit).toHaveBeenCalledTimes(1);