From e4030868b48e0903fa7bdcb5d2f681ddad518c11 Mon Sep 17 00:00:00 2001 From: RaymondVerhoef Date: Mon, 25 May 2026 19:46:04 +0200 Subject: [PATCH] fix --- src/pages/Testen.jsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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.

+ +
+ ); + } + const selectedAnswer = answers[q.id]; const isCorrect = selectedAnswer === q.correctIndex; const progress = ((currentQ + (showFeedback ? 1 : 0)) / quiz.questions.length) * 100;