diff --git a/src/pages/Testen.jsx b/src/pages/Testen.jsx index ca7885f..a4c152b 100644 --- a/src/pages/Testen.jsx +++ b/src/pages/Testen.jsx @@ -98,6 +98,9 @@ const Testen = () => { setError(null); try { const q = await generateWeeklyQuiz(currentUser.id, weekNumber); + if (!q?.questions?.length) { + throw new Error('No questions could be generated for this week. Please try again.'); + } setQuiz(q); setCurrentQ(0); setAnswers({}); @@ -323,6 +326,17 @@ const Testen = () => { // ─── Active Quiz ────────────────────────────────────────── if (phase === 'quiz' && quiz) { const q = quiz.questions[currentQ]; + + // Safety guard — should never happen, but prevents a crash if questions array is empty + if (!q) { + return ( +
Something went wrong loading this question.
+ +