Skip to content

Commit 2597f03

Browse files
committed
improve error handling on courses lookup
1 parent da54cbf commit 2597f03

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

packages/platform-ui/src/views/Courses.vue

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import CourseEditor from '@/components/Courses/CourseEditor.vue';
8585
import CourseStubCard from '@/components/Courses/CourseStubCard.vue';
8686
import _ from 'lodash';
8787
import serverRequest from '../server';
88-
import { ServerRequestType, CourseConfig } from '@vue-skuilder/common';
88+
import { ServerRequestType, CourseConfig, Status } from '@vue-skuilder/common';
8989
import { alertUser } from '@vue-skuilder/common-ui';
9090
import { UserDBInterface, getDataLayer } from '@vue-skuilder/db';
9191
import { getCurrentUser } from '@/stores/useAuthStore';
@@ -176,28 +176,36 @@ export default defineComponent({
176176
177177
async refreshData(): Promise<void> {
178178
console.log(`Pulling user course data...`);
179-
const userCourseIDs = (await this.user!.getCourseRegistrationsDoc()).courses
180-
.filter((c) => {
181-
return c.status === 'active' || c.status === 'maintenance-mode' || c.status === undefined;
182-
})
183-
.map((c) => {
184-
return c.courseID;
185-
});
186-
console.log(`userCourseIDs: ${userCourseIDs}`);
179+
try {
180+
const userCourseIDs = (await this.user!.getCourseRegistrationsDoc()).courses
181+
.filter((c) => {
182+
return c.status === 'active' || c.status === 'maintenance-mode' || c.status === undefined;
183+
})
184+
.map((c) => {
185+
return c.courseID;
186+
});
187+
console.log(`userCourseIDs: ${userCourseIDs}`);
187188
188-
this.existingCourses = (await getDataLayer().getCoursesDB().getCourseList()) as DBCourseConfig[];
189+
this.existingCourses = (await getDataLayer().getCoursesDB().getCourseList()) as DBCourseConfig[];
190+
console.log(`existingCourses: \n\t${this.existingCourses.map((c) => c.name).join(',\n\t')}`);
189191
190-
this.registeredCourses = this.existingCourses.filter((course) => {
191-
let match: boolean = false;
192-
userCourseIDs.forEach((id: string) => {
193-
if (course.courseID === id) {
194-
match = true;
195-
}
192+
this.registeredCourses = this.existingCourses.filter((course) => {
193+
let match: boolean = false;
194+
userCourseIDs.forEach((id: string) => {
195+
if (course.courseID === id) {
196+
match = true;
197+
}
198+
});
199+
return match;
196200
});
197-
return match;
198-
});
201+
} catch (e) {
202+
console.error(`Error refreshing course data:`, e);
203+
alertUser({
204+
status: Status.error,
205+
text: `Failed to load courses: ${e.message || 'Database access error'}`,
206+
});
207+
}
199208
},
200-
201209
async createCourse(): Promise<void> {
202210
this.awaitingCreateCourse = true;
203211
const resp = await serverRequest({

0 commit comments

Comments
 (0)