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;