Skip to content

Conversation

@AlexisMora
Copy link

@AlexisMora AlexisMora commented Feb 9, 2026

What is Changed / Added

An interceptor has been added to the drive-server-client (Which underneath uses axios) to handle the 429 'Too many request' issue.
Now, uppon recieving a 429 error, it will add a wait mechanism so that concurrent calls can also wait for the limit to reset, having a "jitter" time so that all of the awaited requests dont just retry all at the same time.
It has been added a retry mechanism of max 3 times.


Why

Currently this scenario wasnt being handled and the current client was just throwing the error up

@AlexisMora AlexisMora self-assigned this Feb 9, 2026
@AlexisMora AlexisMora added bug Something isn't working enhancement New feature or request labels Feb 9, 2026
@AlexisMora AlexisMora requested a review from egalvis27 February 9, 2026 13:02
Comment on lines 4 to 6
afterEach(() => {
vi.restoreAllMocks();
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to our configuration, it is no longer necessary to use this, as it is done automatically.

} as any;

beforeEach(() => {
vi.clearAllMocks();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

it('should create a request interceptor with a fresh delay state', () => {
attachRateLimiterInterceptors(instance);

expect(createRequestInterceptor).toHaveBeenCalledWith({ pending: null });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some new helpers called call, calls that we can use to validate function calls. Call is used together with toMatchObject to validate the parameters passed to the function.

They are useful for improving the readability of tests and are specialized for this purpose. They are useful for changing the expect that use toHaveBeenCallWith.

Comment on lines 65 to 68
const delayStatePassedToRequest = (createRequestInterceptor as Mock).mock.calls[0][0];
const delayStatePassedToResponse = (createResponseInterceptor as Mock).mock.calls[0][2];

expect(delayStatePassedToRequest).toBe(delayStatePassedToResponse);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation is a bit unusual. Here, you could also use the helper call.

let retryResponse: AxiosResponse;

beforeEach(() => {
vi.clearAllMocks();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line


const result = await onRejected(error);

expect(addJitter).toHaveBeenCalledWith(3000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new call helper

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@AlexisMora
Copy link
Author

AlexisMora commented Feb 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions 1 Security Hotspot

See analysis details on SonarQube Cloud

This issue does not seem to be important,we are using Math.random() to add a bit of "randomness" to the wait time for the request so that the requests waiting for the limit to reset do not fire at the same time.
Matter of fact, this is what sonarcloud is stating:

Status: To Review
This Security Hotspot needs to be reviewed to assess whether the code poses a risk.


await onRejected(error);

call(addJitter).toEqual(5000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change toEqual to toStrictEqual

await expect(onRejected(error)).rejects.toBe(error);
expect(updateStateFromHeaders).not.toHaveBeenCalled();
expect(addJitter).not.toHaveBeenCalled();
expect(waitForDelay).not.toHaveBeenCalled();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change toHaveBeenCalled() to toBeCalled()

@AlexisMora AlexisMora merged commit 9e7a39f into main Feb 9, 2026
6 of 7 checks passed
@AlexisMora AlexisMora deleted the fix/rate-limit-api branch February 9, 2026 17:17
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants