убрал редирект

This commit is contained in:
Joe_Peach committed 2026-04-05 21:22:42 +03:00
1 parent 8e7a687ab3
commit e75023f15a
1 file changed
+29 -8
+29 -8
View File
@@ -10,18 +10,39 @@ class ApiClient {
headers: {
'Content-Type': 'application/json',
},
maxRedirects: 0,
validateStatus: (status) => status >= 200 && status < 400,
});
this.axiosInstance.interceptors.request.use(
(config) => {
if (config.baseURL && config.baseURL.startsWith('http://')) {
console.error('❌ Request uses HTTP instead of HTTPS:', config.baseURL);
config.baseURL = config.baseURL.replace('http://', 'https://');
this.axiosInstance.interceptors.response.use(
(response) => response,
async (error) => {
// Если это редирект (301, 302, 307, 308)
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;
},
(error) => Promise.reject(error)
return Promise.reject(error);
}
);
this.axiosInstance.interceptors.response.use(
(response) => response,