Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss] Use ['Retry-After'] header value without rounding off #1763

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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