Skip to content

Commit

Permalink
[sitecore-jss] Use 'Retry-After' header value without rounding off (#…
Browse files Browse the repository at this point in the history
…1763)

* use retry-header value without rounding off

* update changelog
  • Loading branch information
addy-pathania authored Mar 20, 2024
1 parent 3453ed9 commit 1e6cbdd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions packages/sitecore-jss/src/graphql-request-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/sitecore-jss/src/graphql-request-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1e6cbdd

Please sign in to comment.