Skip to content

Commit

Permalink
fix: validate if a cause exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed May 9, 2024
1 parent 8409aa9 commit 0c45294
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions config/image-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ fetch(
break;
} catch (error) {
if (
!didRetryUnauthorized &&
error.cause &&
error.cause.code == 'UND_ERR_RESPONSE_STATUS_CODE' &&
(error.cause.statusCode === 401 || error.cause.statusCode === 403) &&
!didRetryUnauthorized
(error.cause.statusCode === 401 || error.cause.statusCode === 403)
) {
// GCS token is probably expired. Force a token refresh before trying again.
process.env['IMAGE_CACHE_GCS_AUTH_TOKEN'] = undefined;
Expand All @@ -126,12 +127,14 @@ fetch(
console.error(error);
let exitCode = 1;
if (
error.cause.code == 'UND_ERR_HEADERS_TIMEOUT' ||
error.cause.code == 'UND_ERR_BODY_TIMEOUT' ||
error.cause.code == 'UND_ERR_CONNECT_TIMEOUT'
error.cause &&
(error.cause.code == 'UND_ERR_HEADERS_TIMEOUT' ||
error.cause.code == 'UND_ERR_BODY_TIMEOUT' ||
error.cause.code == 'UND_ERR_CONNECT_TIMEOUT')
) {
exitCode = 2;
} else if (
error.cause &&
error.cause.code == 'UND_ERR_RESPONSE_STATUS_CODE' &&
error.cause.statusCode === 429
) {
Expand Down

0 comments on commit 0c45294

Please sign in to comment.