feat: Add detailed HTTP status code error handling for fetch requests and enhance displayed error messages with console logging.
This commit is contained in:
27
index.html
27
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";
|
||||
|
||||
Reference in New Issue
Block a user