From 8582f6f5d876c4fdd714746fa4f1f1b34f7824b9 Mon Sep 17 00:00:00 2001 From: Tom Sightler Date: Sun, 27 Oct 2024 22:24:07 -0400 Subject: [PATCH] Log fetch errors only on retries --- packages/ring-client-api/rest-client.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/ring-client-api/rest-client.ts b/packages/ring-client-api/rest-client.ts index efba8447..e9d98715 100644 --- a/packages/ring-client-api/rest-client.ts +++ b/packages/ring-client-api/rest-client.ts @@ -91,7 +91,7 @@ async function responseToError(response: Response) { async function requestWithRetry( requestOptions: RequestOptions & { url: string; allowNoResponse?: boolean }, - isRetry = false, + retryCount = 0, ): Promise { try { if (requestOptions.json || requestOptions.responseType === 'json') { @@ -154,18 +154,18 @@ async function requestWithRetry( return data } catch (e: any) { if (!e.response && !requestOptions.allowNoResponse) { - if (isRetry) { - const message = 'Error: ' + e.message + - (e.cause?.message ? ', Cause: ' + e.cause.message : '') + - (e.cause?.code ? ', Code: ' + e.cause.code : ''); + if (retryCount > 0) { + let detailedError = `Error: ${e.message}` + detailedError += e.cause?.message ? `, Cause: ${e.cause.message}` : '' + detailedError += e.cause?.code ? `, Code: ${e.cause.code}` : '' logError( - `Failed to reach Ring server at ${requestOptions.url}. ${message}. Trying again in 5 seconds...`, + `Retry #${retryCount} failed to reach Ring server at ${requestOptions.url}. ${detailedError}. Trying again in 5 seconds...`, ) if (e.message.includes('NGHTTP2_ENHANCE_YOUR_CALM')) { logError( `There is a known issue with your current NodeJS version (${process.version}). Please see https://github.com/dgreif/ring/wiki/NGHTTP2_ENHANCE_YOUR_CALM-Error for details`, ) - } else if ((e.message.includes('fetch is not defined'))) { + } else if (e.message.includes('fetch is not defined')) { logError( `Your current NodeJS version (${process.version}) is too old to support this plugin. Please upgrade to the latest LTS version of NodeJS.`, ) @@ -174,7 +174,7 @@ async function requestWithRetry( } await delay(5000) - return requestWithRetry(requestOptions, true) + return requestWithRetry(requestOptions, retryCount + 1) } throw e }