From 3f0a649231fbc59fe6bb5363e756651cd66540cf Mon Sep 17 00:00:00 2001 From: Tom Sightler Date: Sun, 27 Oct 2024 20:31:36 -0400 Subject: [PATCH] Suppress single fetch failures from log --- packages/ring-client-api/rest-client.ts | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/ring-client-api/rest-client.ts b/packages/ring-client-api/rest-client.ts index e646d38b..efba8447 100644 --- a/packages/ring-client-api/rest-client.ts +++ b/packages/ring-client-api/rest-client.ts @@ -91,6 +91,7 @@ async function responseToError(response: Response) { async function requestWithRetry( requestOptions: RequestOptions & { url: string; allowNoResponse?: boolean }, + isRetry = false, ): Promise { try { if (requestOptions.json || requestOptions.responseType === 'json') { @@ -153,25 +154,27 @@ async function requestWithRetry( return data } catch (e: any) { if (!e.response && !requestOptions.allowNoResponse) { - const message = 'Error: ' + e.message + - (e.cause?.message ? ', Cause: ' + e.cause.message : '') + - (e.cause?.code ? ', Code: ' + e.cause.code : ''); - logError( - `Failed to reach Ring server at ${requestOptions.url}. ${message}. 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'))) { + if (isRetry) { + const message = 'Error: ' + e.message + + (e.cause?.message ? ', Cause: ' + e.cause.message : '') + + (e.cause?.code ? ', Code: ' + e.cause.code : ''); logError( - `Your current NodeJS version (${process.version}) is too old to support this plugin. Please upgrade to the latest LTS version of NodeJS.`, + `Failed to reach Ring server at ${requestOptions.url}. ${message}. 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'))) { + logError( + `Your current NodeJS version (${process.version}) is too old to support this plugin. Please upgrade to the latest LTS version of NodeJS.`, + ) + } + logDebug(e) } - logDebug(e) await delay(5000) - return requestWithRetry(requestOptions) + return requestWithRetry(requestOptions, true) } throw e }