From 96e493372002dd44998ac2be06c7249b7c2ea05e Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Sun, 31 Oct 2021 19:26:57 -0700 Subject: [PATCH] feat: Add retry support for 504 (Gateway Timeout) Fixes a downstream issue https://github.com/googleapis/nodejs-storage/issues/1635 by adding support for gateway timeouts - which is also compliant with https://cloud.google.com/storage/docs/retry-strategy#idempotency-operations --- src/util.ts | 2 +- test/util.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 88f756bf..b83e5b48 100644 --- a/src/util.ts +++ b/src/util.ts @@ -544,7 +544,7 @@ export class Util { */ shouldRetryRequest(err?: ApiError) { if (err) { - if ([408, 429, 500, 502, 503].indexOf(err.code!) !== -1) { + if ([408, 429, 500, 502, 503, 504].indexOf(err.code!) !== -1) { return true; } diff --git a/test/util.ts b/test/util.ts index 0d16f944..fb265259 100644 --- a/test/util.ts +++ b/test/util.ts @@ -1204,6 +1204,12 @@ describe('common/util', () => { assert.strictEqual(util.shouldRetryRequest(error), true); }); + it('should return true with error code 504', () => { + const error = new ApiError('504'); + error.code = 504; + assert.strictEqual(util.shouldRetryRequest(error), true); + }); + it('should detect rateLimitExceeded reason', () => { const rateLimitError = new ApiError('Rate limit error without code.'); rateLimitError.errors = [{reason: 'rateLimitExceeded'}];