Report OpenAI quota errors in admin

This commit is contained in:
rajchales-monito
2026-07-29 21:55:25 +02:00
parent f93c92cd96
commit aaffbb3079
3 changed files with 57 additions and 10 deletions
+15 -2
View File
@@ -431,14 +431,23 @@ async function testOpenAiKey() {
setOpenAiStatus("Testuji OpenAI klic...");
const result = await api("/api/admin/ai/test", { method: "POST" }).catch((error) => error);
if (result?.ok) {
setOpenAiStatus(`Klic funguje (${result.key || "sk-..."}), dostupnych modelu: ${result.modelCount}.`);
setOpenAiStatus(`Klic funguje (${result.key || "sk-..."}), model ${result.model || "AI"} umi prekladat.`);
await loadAiModels().catch(() => {});
return;
}
const message = result?.error === "missing_openai_api_key"
? "Klic neni ulozeny. Nejdřív ho vloz a klikni na Ulozit AI nastaveni."
: `Test selhal (${result?.error || "neznamá chyba"}).`;
setOpenAiStatus(message);
setOpenAiStatus(openAiTestMessage(result) || message);
}
function openAiTestMessage(result) {
if (result?.error === "missing_openai_api_key") return "Klic neni ulozeny. Nejdriiv ho vloz a klikni na Ulozit AI nastaveni.";
if (result?.error === "quota_exceeded") return "OpenAI klic je ulozeny, ale chybi kredit nebo billing. Preklady zatim nepobezi.";
if (result?.error === "invalid_key") return "OpenAI klic je spatny nebo nema pristup. Vloz novy klic.";
if (result?.error === "bad_model") return "Zvoleny OpenAI model neni dostupny pro tento klic. Vyber jiny model.";
if (result?.error === "rate_limited") return "OpenAI docasne omezuje pozadavky. Zkus test za chvili.";
return "";
}
function setOpenAiStatus(message) {
@@ -624,6 +633,10 @@ function translationStatusLabel(status, source, target) {
if (status === "translated") return `preklad: ${source} -> ${target}`;
if (status === "same_language") return `preklad: ${source} = ${target}`;
if (status === "failed") return `preklad: ${source} -> ${target} - chyba`;
if (status === "quota_exceeded") return "preklad: neni kredit";
if (status === "invalid_key") return "preklad: spatny klic";
if (status === "bad_model") return "preklad: spatny model";
if (status === "rate_limited") return "preklad: limit API";
if (status === "missing_key") return "preklad: chybi klic";
if (status === "disabled") return "preklad: vypnuto";
if (status === "empty") return `preklad: ${source} -> ${target} - prazdny`;