From c3a85bf52801942e07c79d81f100b4803ff286de Mon Sep 17 00:00:00 2001 From: Luis Carlos Aveiro Date: Sat, 10 Aug 2024 14:12:39 +0100 Subject: [PATCH] fix: resolve typescript:S6582 --- code/src/http/httpClient.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/code/src/http/httpClient.ts b/code/src/http/httpClient.ts index 4af8d6e..e41eadb 100644 --- a/code/src/http/httpClient.ts +++ b/code/src/http/httpClient.ts @@ -331,6 +331,21 @@ export default class HttpClient { return this.sendRequest('HEAD'); } + /** + * Determine if response is successful. + * + * @param {Response} response + * + * @returns {boolean} + */ + private isSuccessfulResponse(response?: Response): boolean { + if (response === undefined) { + return false; + } + + return response.ok; + } + /** * Process a OPTIONS request to the given URL. * @@ -490,7 +505,7 @@ export default class HttpClient { try { const response: Response = await this.attemptRequest(method); - const successfulResponse: boolean = response !== undefined && response.ok; + const successfulResponse: boolean = this.isSuccessfulResponse(response); const shouldRetry = this.retryCallback ? this.retryCallback(response, this) : true; if (!successfulResponse && shouldRetry === true && this.requestAttempts <= this.retries) {