Skip to content

Commit fbc7975

Browse files
authored
fix: do not remove query parameters on retry (#514)
Fixes #513. This is a draft fix intended to start the discussion. I'm not sure if it's okay to remove the existing hack introduced in #483. Before making a decision, I’d like to learn more about the duplicate request parameters problem and how I can reproduce it in a test. @t-col probably you could give me some hints?
1 parent 0afab0f commit fbc7975

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/rate-limit.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ export default function rateLimit(instance: AxiosInstance, maxRetry = 5): void {
8181
delete config.httpAgent
8282
delete config.httpsAgent
8383

84-
/**
85-
* Hack to mitigate (likely) bug introduced in axios v1.7.0 where `url`,
86-
* when using the default `xhr` adapter, is a fully qualified URL (instead of a path),
87-
* which somehow causes the request params to be repeatedly appended
88-
* to the final request URL upon each retry.
89-
*/
90-
config.url = config.url.split('?')[0]
91-
9284
return delay(wait).then(() => instance(config))
9385
}
9486
return Promise.reject(error)

test/unit/rate-limit-test.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,22 @@ it('Rejects errors with strange status codes', async () => {
169169
expect(logHandlerStub).toBeCalledTimes(0)
170170
}
171171
})
172+
173+
it('Preserves URI query parameters between retries', async () => {
174+
const { client } = setup()
175+
const uri = '/entries?content_type=B&fields.id=1'
176+
177+
mock.onGet(uri).replyOnce(429, 'Rate Limit')
178+
mock.onGet(uri).replyOnce(429, 'Rate Limit')
179+
mock.onGet(uri).replyOnce(200, 'Success')
180+
181+
expect.assertions(5)
182+
183+
const response = await client.get(uri)
184+
expect(response.status).toEqual(200)
185+
186+
expect(mock.history.get.length).toBe(3)
187+
for (const request of mock.history.get) {
188+
expect(request.url).toEqual(uri)
189+
}
190+
})

0 commit comments

Comments
 (0)