Skip to content

Commit

Permalink
Merge pull request #483 from contentful/fix/retries
Browse files Browse the repository at this point in the history
feat: enable 'fetch' adapter + duplicate request params fix
  • Loading branch information
t-col authored Jul 3, 2024
2 parents 514a1cd + 2fcb9f7 commit 706d7b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@types/qs": "^6.9.10",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"axios": "^1.6.0",
"axios": "^1.7.2",
"axios-mock-adapter": "^1.20.0",
"babel-eslint": "^10.1.0",
"bundlesize": "^0.18.1",
Expand Down
10 changes: 9 additions & 1 deletion src/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function rateLimit(instance: AxiosInstance, maxRetry = 5): void {
responseLogger(response)
return response
},
function (error) {
async function (error) {
const { response } = error
const { config } = error
responseLogger(error)
Expand Down Expand Up @@ -81,6 +81,14 @@ export default function rateLimit(instance: AxiosInstance, maxRetry = 5): void {
delete config.httpAgent
delete config.httpsAgent

/**
* Hack to mitigate (likely) bug introduced in axios v1.7.0 where `url`,
* when using the default `xhr` adapter, is a fully qualified URL (instead of a path),
* which somehow causes the request params to be repeatedly appended
* to the final request URL upon each retry.
*/
config.url = config.url.split('?')[0]

return delay(wait).then(() => instance(config))
}
return Promise.reject(error)
Expand Down

0 comments on commit 706d7b6

Please sign in to comment.