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:
@@ -39,7 +39,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 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>
|
||||
<div class="vocab-items">
|
||||
<div v-for="(vocab, index) in importantVocab" :key="index" class="vocab-item">
|
||||
@@ -196,11 +196,15 @@ export default {
|
||||
},
|
||||
importantVocab() {
|
||||
// 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();
|
||||
|
||||
this.lesson.grammarExercises.forEach(exercise => {
|
||||
try {
|
||||
// Extrahiere aus questionData
|
||||
const qData = this.getQuestionData(exercise);
|
||||
const aData = this.getAnswerData(exercise);
|
||||
@@ -228,9 +232,16 @@ export default {
|
||||
vocabMap.set(correct, { learning: correct, reference: correct });
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Fehler beim Extrahieren von Vokabeln aus Übung:', e);
|
||||
}
|
||||
});
|
||||
|
||||
return Array.from(vocabMap.values());
|
||||
} catch (e) {
|
||||
console.error('Fehler in importantVocab computed property:', e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
Reference in New Issue
Block a user