From 1e6cbdd9f77e315e68277766390c6281b96d001d Mon Sep 17 00:00:00 2001 From: Addy Pathania <89087450+sc-addypathania@users.noreply.github.com> Date: Wed, 20 Mar 2024 06:08:04 -0400 Subject: [PATCH] [sitecore-jss] Use 'Retry-After' header value without rounding off (#1763) * use retry-header value without rounding off * update changelog --- CHANGELOG.md | 2 +- .../sitecore-jss/src/graphql-request-client.test.ts | 13 +++++++++++++ packages/sitecore-jss/src/graphql-request-client.ts | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d06dc3f67b..403125f039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ Our versioning strategy is as follows: * Handle additional string error codes like ECONNRESET, ETIMEDOUT, EPROTO. Can configure more using DefaultRetryStrategy. * Retries has now been enabled by default with a default value of 3. It can be disabled by configuring it to 0. * [Retry-After] header now falls back to the default delay time when it comes out to be empty. - ([#1755](https://github.com/Sitecore/jss/pull/1755)) ([#1759](https://github.com/Sitecore/jss/pull/1759)) + ([#1755](https://github.com/Sitecore/jss/pull/1755)) ([#1759](https://github.com/Sitecore/jss/pull/1759)) ([#1763](https://github.com/Sitecore/jss/pull/1763)) ### 🐛 Bug Fixes diff --git a/packages/sitecore-jss/src/graphql-request-client.test.ts b/packages/sitecore-jss/src/graphql-request-client.test.ts index 006fc55e13..f882ddc15b 100644 --- a/packages/sitecore-jss/src/graphql-request-client.test.ts +++ b/packages/sitecore-jss/src/graphql-request-client.test.ts @@ -605,6 +605,19 @@ describe('GraphQLRequestClient', () => { expect(delay).to.equal(expectedDelay); }); + it('should return delay using the value from Retry-After header without rounding off', () => { + const retryStrategy = new DefaultRetryStrategy(); + const mockError = { + response: { + status: 429, + headers: new Map([['Retry-After', '1.5']]), + }, + }; + const delay = retryStrategy.getDelay(mockError, 3); + const expectedDelay = 1.5 * 1000; + expect(delay).to.equal(expectedDelay); + }); + it('should use custom exponential factor', () => { const customFactor = 3; const retryStrategy = new DefaultRetryStrategy({ diff --git a/packages/sitecore-jss/src/graphql-request-client.ts b/packages/sitecore-jss/src/graphql-request-client.ts index a9d0149242..f3bc6f9fa2 100644 --- a/packages/sitecore-jss/src/graphql-request-client.ts +++ b/packages/sitecore-jss/src/graphql-request-client.ts @@ -132,7 +132,7 @@ export class DefaultRetryStrategy implements RetryStrategy { retryAfterHeader !== undefined && retryAfterHeader.trim() !== '' ) { - const delaySeconds = Number.parseInt(retryAfterHeader, 10); + const delaySeconds = Number.parseFloat(retryAfterHeader); return delaySeconds * 1000; } else { return Math.pow(this.factor, attempt - 1) * 1000;