From 38f0464c81f4bddcf83f6d8efe9b02adeec6e8b4 Mon Sep 17 00:00:00 2001 From: Yamen Ahmad Date: Sun, 12 Apr 2026 03:19:29 +0400 Subject: [PATCH] fix: show proper error messages in speaking script generation instead of empty [] Made-with: Cursor --- src/pages/GenerationPage.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/GenerationPage.tsx b/src/pages/GenerationPage.tsx index 8c78355dc..da4709cb1 100644 --- a/src/pages/GenerationPage.tsx +++ b/src/pages/GenerationPage.tsx @@ -294,10 +294,18 @@ export default function GenerationPage() { mutationFn: (params: { topics: string[]; difficulty: string; partIndex: number }) => generationService.generateSpeakingScript({ topics: params.topics.filter(Boolean), difficulty: params.difficulty, part: "speaking_1" }), onSuccess: (res, vars) => { + const r = res as Record; + if (r.error) { + toast({ variant: "destructive", title: "Script generation failed", description: String(r.error) }); + return; + } const st = getModuleState("speaking"); const parts = [...st.speakingParts]; - const r = res as Record; - const script = (r.script as string) ?? JSON.stringify(r.questions ?? res); + const script = (r.script as string) || ""; + if (!script) { + toast({ variant: "destructive", title: "No script returned", description: "AI returned empty response — try again." }); + return; + } parts[vars.partIndex] = { ...parts[vars.partIndex], script }; updateModuleState("speaking", { speakingParts: parts }); toast({ title: "Script generated" });