From 871e81774bb53b7012ceb22ed112cd223441cedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 13 Dec 2021 12:18:38 +0100 Subject: [PATCH] MOBILE-3833 dashboard: Fix WS exceptions on get_recent_courses and grace --- .../block/myoverview/components/myoverview/myoverview.ts | 9 +++++++-- .../recentlyaccessedcourses/recentlyaccessedcourses.ts | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/addons/block/myoverview/components/myoverview/myoverview.ts b/src/addons/block/myoverview/components/myoverview/myoverview.ts index fa7e2f7fa..4d3a0bc78 100644 --- a/src/addons/block/myoverview/components/myoverview/myoverview.ts +++ b/src/addons/block/myoverview/components/myoverview/myoverview.ts @@ -264,8 +264,13 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem this.hasCourses = this.allCourses.length > 0; - this.gradePeriodAfter = parseInt(await this.currentSite.getConfig('coursegraceperiodafter', refresh), 10) || 0; - this.gradePeriodBefore = parseInt(await this.currentSite.getConfig('coursegraceperiodbefore', refresh), 10) || 0; + try { + this.gradePeriodAfter = parseInt(await this.currentSite.getConfig('coursegraceperiodafter', refresh), 10); + this.gradePeriodBefore = parseInt(await this.currentSite.getConfig('coursegraceperiodbefore', refresh), 10); + } catch { + this.gradePeriodAfter = 0; + this.gradePeriodBefore = 0; + } this.loadSort(); this.loadLayouts(config?.layouts?.value.split(',')); diff --git a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts index 6bbad0d5d..9eaa906e6 100644 --- a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts +++ b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts @@ -135,14 +135,16 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories && this.block.configsRecord.displaycategories.value == '1'; - // WS is failing on 3.7 and 3.6, use a fallback. - if (!this.site.isVersionGreaterEqualThan('3.8')) { + let recentCourses: CoreCourseSummaryData[] = []; + try { + recentCourses = await CoreCourses.getRecentCourses(); + } catch { + // WS is failing on 3.7 and bellow, use a fallback. this.courses = await CoreCoursesHelper.getUserCoursesWithOptions('lastaccess', 10, undefined, showCategories); return; } - const recentCourses = await CoreCourses.getRecentCourses(); const courseIds = recentCourses.map((course) => course.id); // Get the courses using getCoursesByField to get more info about each course.