Skip to content

Commit

Permalink
Suppress single fetch failures from log
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Sightler committed Oct 28, 2024
1 parent be4ea1a commit 3f0a649
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/ring-client-api/rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async function responseToError(response: Response) {

async function requestWithRetry<T>(
requestOptions: RequestOptions & { url: string; allowNoResponse?: boolean },
isRetry = false,
): Promise<T & ExtendedResponse> {
try {
if (requestOptions.json || requestOptions.responseType === 'json') {
Expand Down Expand Up @@ -153,25 +154,27 @@ async function requestWithRetry<T>(
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 +

Check failure on line 158 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `·'Error:·'·+` with `⏎··········'Error:·'·+⏎·········`

Check failure on line 158 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (18)

Replace `·'Error:·'·+` with `⏎··········'Error:·'·+⏎·········`

Check failure on line 158 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (22)

Replace `·'Error:·'·+` with `⏎··········'Error:·'·+⏎·········`
(e.cause?.message ? ', Cause: ' + e.cause.message : '') +
(e.cause?.code ? ', Code: ' + e.cause.code : '');

Check failure on line 160 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (20)

Extra semicolon

Check failure on line 160 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (20)

Delete `;`

Check failure on line 160 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (18)

Extra semicolon

Check failure on line 160 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (18)

Delete `;`

Check failure on line 160 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (22)

Extra semicolon

Check failure on line 160 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (22)

Delete `;`
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'))) {

Check failure on line 168 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (20)

Replace `(e.message.includes('fetch·is·not·defined')` with `e.message.includes('fetch·is·not·defined'`

Check failure on line 168 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (18)

Replace `(e.message.includes('fetch·is·not·defined')` with `e.message.includes('fetch·is·not·defined'`

Check failure on line 168 in packages/ring-client-api/rest-client.ts

View workflow job for this annotation

GitHub Actions / build (22)

Replace `(e.message.includes('fetch·is·not·defined')` with `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
}
Expand Down

0 comments on commit 3f0a649

Please sign in to comment.