From 118fa3961f8db1f03d5697e6fbc75e9b7f4de9db Mon Sep 17 00:00:00 2001 From: dmitriylaukhin Date: Mon, 6 Jul 2026 13:45:12 +0500 Subject: [PATCH] Surface regenerate errors in clean-pdf Zotero section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit regenerate() silently did nothing on {ok:false} or a rejected server action, risking an unhandled promise rejection and leaving the student staring at a stuck "меняем…" button with no feedback. Wrap the action call in try/catch and show an inline error message on failure. --- .../(student)/tools/clean-pdf/ZoteroSection.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx b/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx index 74d9e31..b1ee081 100644 --- a/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx +++ b/src/app/(student)/tools/clean-pdf/ZoteroSection.tsx @@ -8,6 +8,7 @@ export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: st const [key, setKey] = useState(apiKey); const [revealed, setRevealed] = useState(false); const [pending, startTransition] = useTransition(); + const [error, setError] = useState(null); const shownKey = revealed ? key : key.slice(0, 8) + "…" + key.slice(-4); const curlExample = `curl -H "Authorization: Bearer ${key}" \\\n "${baseUrl}/api/pdf?url=https://example.com/article&format=A4&theme=light" \\\n -o article.pdf`; @@ -15,9 +16,19 @@ export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: st function regenerate() { if (!confirm("Старый ключ перестанет работать (в том числе в Zotero). Продолжить?")) return; + setError(null); startTransition(async () => { - const res = await regeneratePdfApiKey(); - if (res.ok && res.key) { setKey(res.key); setRevealed(true); } + try { + const res = await regeneratePdfApiKey(); + if (res.ok && res.key) { + setKey(res.key); + setRevealed(true); + } else { + setError("Не удалось перевыпустить ключ, попробуйте ещё раз"); + } + } catch { + setError("Не удалось перевыпустить ключ, попробуйте ещё раз"); + } }); } @@ -40,6 +51,7 @@ export function ZoteroSection({ apiKey, baseUrl }: { apiKey: string; baseUrl: st

Ключ персональный — не публикуйте его. Если ключ утёк, перевыпустите: старый сразу отключится.

+ {error &&

{error}

}