fix: show proper error messages in speaking script generation instead of empty []

Made-with: Cursor
This commit is contained in:
Yamen Ahmad
2026-04-12 03:19:29 +04:00
parent b9f13fe59c
commit 38f0464c81

View File

@@ -294,10 +294,18 @@ export default function GenerationPage() {
mutationFn: (params: { topics: string[]; difficulty: string; partIndex: number }) => mutationFn: (params: { topics: string[]; difficulty: string; partIndex: number }) =>
generationService.generateSpeakingScript({ topics: params.topics.filter(Boolean), difficulty: params.difficulty, part: "speaking_1" }), generationService.generateSpeakingScript({ topics: params.topics.filter(Boolean), difficulty: params.difficulty, part: "speaking_1" }),
onSuccess: (res, vars) => { onSuccess: (res, vars) => {
const r = res as Record<string, unknown>;
if (r.error) {
toast({ variant: "destructive", title: "Script generation failed", description: String(r.error) });
return;
}
const st = getModuleState("speaking"); const st = getModuleState("speaking");
const parts = [...st.speakingParts]; const parts = [...st.speakingParts];
const r = res as Record<string, unknown>; const script = (r.script as string) || "";
const script = (r.script as string) ?? JSON.stringify(r.questions ?? res); if (!script) {
toast({ variant: "destructive", title: "No script returned", description: "AI returned empty response — try again." });
return;
}
parts[vars.partIndex] = { ...parts[vars.partIndex], script }; parts[vars.partIndex] = { ...parts[vars.partIndex], script };
updateModuleState("speaking", { speakingParts: parts }); updateModuleState("speaking", { speakingParts: parts });
toast({ title: "Script generated" }); toast({ title: "Script generated" });