From e75023f15ae6479d2e4fa04ea5d9f7a0b642215c Mon Sep 17 00:00:00 2001 From: Oleg Urin Date: Sun, 5 Apr 2026 21:22:42 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/client.ts | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) 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,