Open petrprikryl opened 5 months ago
i have the same problem. i update the newest version. this still happened
I temporarily used the following method to avoid this issue. I'm not sure if there's a better way to handle it.
instance.interceptors.request.use(conf => {
const config: InternalAxiosRequestConfig = { ...conf };
// set request id
const requestId = nanoid();
config.headers.set(REQUEST_ID_KEY, requestId);
// retry bug fix
clearDuplicatedQueryString(config);
// config cancel token
const cancelTokenSource = axios.CancelToken.source();
config.cancelToken = cancelTokenSource.token;
cancelTokenSourceMap.set(requestId, cancelTokenSource);
// handle config by hook
return opts.onRequest?.(config) || config;
});
// Clear duplicate query string parameters
function clearDuplicatedQueryString(config: InternalAxiosRequestConfig) {
const isAbsoluteURL = /^https?:\/\//i.test(config.url!);
if (isAbsoluteURL) config.params = {};
}
instance.interceptors.request.use((config) => {
console.log(config);
return config;
});
On the first request it will return config.url with just the path -
But when I log the response from on onRetry
axiosRetry(instance, {
retries: 3,
retryCondition: (e) => isNetworkOrIdempotentRequestError(e),
onRetry: (retryCount, error, requestConfig) => {
console.log(requestConfig);
},
});
requestConfig.url returns the absolute url; tried to track down if it's axios-retry or axios that is changing the url from a path to absolute but was unable to
can i ask, how are you guys forming the url like /api?foo=bar
and /api?foo=bar&foo=bar
?
config.url
and config.baseURL
return the server URL that will be used for the request (not including params) and config.params
is an object (so it shouldn't have duplicated keys).
i can't seem to figure out 🙈
在请求拦截器中添加以下代码,可以优雅的解决你的问题
instance.interceptors.request.use(config => {
config.url = config.url.split('?')[0]
return config;
});
First request will be:
/api?foo=bar
Second:/api?foo=bar&foo=bar
...