From 0b4507e2d21cb3f0f39673a89d6672f81f10ee39 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Mon, 23 Mar 2026 23:00:52 +0700 Subject: [PATCH] =?UTF-8?q?fix(rates):=20fallback=20=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D1=8F=D0=BC=D0=BE=D0=B9=20fetch=20=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=BE=D0=BA=D1=81=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- src/App.jsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index bfb9c2a..357f121 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -56,18 +56,20 @@ function App() { if (!settings?.ratesUrl) { return } - const proxyUrl = `/api/rates-proxy?url=${encodeURIComponent(settings.ratesUrl)}` - fetch(proxyUrl) - .then((response) => { - if (!response.ok) { - throw new Error('Не удалось получить курсы валют') - } - return response.json() - }) - .then((payload) => { - setRatesData(normalizeRatesPayload(payload) ?? payload) - setRatesError('') + const directUrl = settings.ratesUrl + const proxyUrl = `/api/rates-proxy?url=${encodeURIComponent(directUrl)}` + const handlePayload = (payload) => { + setRatesData(normalizeRatesPayload(payload) ?? payload) + setRatesError('') + } + const fetchJson = (url) => + fetch(url).then((r) => { + if (!r.ok) throw new Error(`HTTP ${r.status}`) + return r.json() }) + fetchJson(proxyUrl) + .then(handlePayload) + .catch(() => fetchJson(directUrl).then(handlePayload)) .catch((error) => { setRatesError(error.message || 'Ошибка загрузки курсов') })