diff --git a/src/api/client.ts b/src/api/client.ts index fa03c20..6bd3591 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -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,