From 3ed4a4e985e90928e9f3d1c4b182d6bd9bcf27c2 Mon Sep 17 00:00:00 2001 From: almazlar Date: Sun, 8 Feb 2026 16:21:21 +0300 Subject: [PATCH] feat: Add detailed HTTP status code error handling for fetch requests and enhance displayed error messages with console logging. --- index.html | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 66f741e..895bcf2 100644 --- a/index.html +++ b/index.html @@ -246,12 +246,23 @@ }) }); + const status = response.status; + const statusText = response.statusText; + + if (status === 404) { + throw new Error("Sunucu bulunamadı. Lütfen API adresini kontrol edin."); + } else if (status === 500) { + throw new Error("Sunucu hata verdi. Lütfen daha sonra tekrar deneyin."); + } else if (!response.ok) { + throw new Error(`HTTP hata: ${status} - ${statusText}`); + } + const data = await response.json(); rawDescription = data.response; resultText.innerText = rawDescription; document.getElementById('translateBtn').style.display = "block"; } catch (err) { - resultText.innerText = "Hata: Sunucuya ulaşılamadı. Nginx veya Ollama ayarlarını kontrol edin."; + resultText.innerText = "Hata: Sunucuya ulaşılamadı. Nginx veya Ollama ayarlarını kontrol edin." + err.message; console.error(err); } finally { btn.innerHTML = "Yeniden Analiz Et"; @@ -284,10 +295,22 @@ }) }); + const status = response.status; + const statusText = response.statusText; + + if (status === 404) { + throw new Error("Sunucu bulunamadı. Lütfen API adresini kontrol edin."); + } else if (status === 500) { + throw new Error("Sunucu hata verdi. Lütfen daha sonra tekrar deneyin."); + } else if (!response.ok) { + throw new Error(`HTTP hata: ${status} - ${statusText}`); + } + const data = await response.json(); trText.innerText = data.response; } catch (err) { - trText.innerText = "Hata: Çeviri servisi yanıt vermiyor."; + trText.innerText = "Hata: Çeviri servisi yanıt vermiyor." + err.message; + console.error(err); } finally { transBtn.disabled = false; transBtn.innerHTML = "Türkçeye Çevir";