Improve error handling and validation in importantVocab computed property of VocabLessonView

- Added checks to ensure importantVocab is only processed if lesson and grammarExercises are valid.
- Enhanced error handling with try-catch blocks to log issues during vocabulary extraction, improving robustness.
- Updated the condition for rendering the vocabulary list to prevent errors when importantVocab is undefined.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 19:01:49 +01:00
parent 196b74bebb
commit 0331ffeb93

View File

@@ -39,7 +39,7 @@
</div> </div>
<!-- Wichtige Begriffe aus den Übungen --> <!-- Wichtige Begriffe aus den Übungen -->
<div v-if="importantVocab.length > 0" class="vocab-list"> <div v-if="importantVocab && importantVocab.length > 0" class="vocab-list">
<h4>{{ $t('socialnetwork.vocab.courses.importantVocab') }}</h4> <h4>{{ $t('socialnetwork.vocab.courses.importantVocab') }}</h4>
<div class="vocab-items"> <div class="vocab-items">
<div v-for="(vocab, index) in importantVocab" :key="index" class="vocab-item"> <div v-for="(vocab, index) in importantVocab" :key="index" class="vocab-item">
@@ -196,11 +196,15 @@ export default {
}, },
importantVocab() { importantVocab() {
// Extrahiere wichtige Begriffe aus den Übungen // Extrahiere wichtige Begriffe aus den Übungen
if (!this.lesson || !this.lesson.grammarExercises) return []; try {
if (!this.lesson || !this.lesson.grammarExercises || !Array.isArray(this.lesson.grammarExercises)) {
return [];
}
const vocabMap = new Map(); const vocabMap = new Map();
this.lesson.grammarExercises.forEach(exercise => { this.lesson.grammarExercises.forEach(exercise => {
try {
// Extrahiere aus questionData // Extrahiere aus questionData
const qData = this.getQuestionData(exercise); const qData = this.getQuestionData(exercise);
const aData = this.getAnswerData(exercise); const aData = this.getAnswerData(exercise);
@@ -228,9 +232,16 @@ export default {
vocabMap.set(correct, { learning: correct, reference: correct }); vocabMap.set(correct, { learning: correct, reference: correct });
} }
} }
} catch (e) {
console.warn('Fehler beim Extrahieren von Vokabeln aus Übung:', e);
}
}); });
return Array.from(vocabMap.values()); return Array.from(vocabMap.values());
} catch (e) {
console.error('Fehler in importantVocab computed property:', e);
return [];
}
} }
}, },
computed: { computed: {