убрал редирект
This commit is contained in:
1 parent
8e7a687ab3
commit
e75023f15a
1 file changed
+29
-8
+29
-8
@@ -10,18 +10,39 @@ class ApiClient {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
maxRedirects: 0,
|
||||||
|
validateStatus: (status) => status >= 200 && status < 400,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.axiosInstance.interceptors.request.use(
|
this.axiosInstance.interceptors.response.use(
|
||||||
(config) => {
|
(response) => response,
|
||||||
if (config.baseURL && config.baseURL.startsWith('http://')) {
|
async (error) => {
|
||||||
console.error('❌ Request uses HTTP instead of HTTPS:', config.baseURL);
|
// Если это редирект (301, 302, 307, 308)
|
||||||
config.baseURL = config.baseURL.replace('http://', 'https://');
|
if (error.response && [301, 302, 307, 308].includes(error.response.status)) {
|
||||||
|
const location = error.response.headers.location;
|
||||||
|
console.log('🔄 Redirect detected:', location);
|
||||||
|
|
||||||
|
if (location) {
|
||||||
|
// Исправляем HTTP на HTTPS
|
||||||
|
let fixedLocation = location;
|
||||||
|
if (fixedLocation.startsWith('http://')) {
|
||||||
|
fixedLocation = fixedLocation.replace('http://', 'https://');
|
||||||
|
console.log('✅ Fixed URL:', fixedLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Повторяем запрос на исправленный URL
|
||||||
|
try {
|
||||||
|
const response = await this.axiosInstance.get(fixedLocation);
|
||||||
|
return response;
|
||||||
|
} catch (retryError) {
|
||||||
|
return Promise.reject(retryError);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return config;
|
return Promise.reject(error);
|
||||||
},
|
}
|
||||||
(error) => Promise.reject(error)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.axiosInstance.interceptors.response.use(
|
this.axiosInstance.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
|
|||||||
Reference in new issue
Block a user