From 8360f5793df23ed6f2a9de8bf9f38ce115156c84 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 24 May 2022 08:06:20 +0200 Subject: [PATCH] MOBILE-4067 home: Display Dashboard if WS call fails --- src/core/features/courses/pages/my/my.ts | 5 ++++- .../services/handlers/dashboard-home.ts | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/core/features/courses/pages/my/my.ts b/src/core/features/courses/pages/my/my.ts index 56551726e..5bc3723d3 100644 --- a/src/core/features/courses/pages/my/my.ts +++ b/src/core/features/courses/pages/my/my.ts @@ -20,6 +20,7 @@ import { CoreCoursesDashboard, CoreCoursesDashboardProvider } from '@features/co import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager'; import { IonRefresher } from '@ionic/angular'; import { CoreSites } from '@services/sites'; +import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreCourses } from '../../services/courses'; @@ -90,7 +91,9 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy { await CoreUtils.nextTicks(2); this.myOverviewBlock = this.block?.dynamicComponent?.instance as AddonBlockMyOverviewComponent; - } catch { + } catch (error) { + CoreDomUtils.showErrorModal(error); + // Cannot get the blocks, just show the block if needed. this.loadFallbackBlock(); } diff --git a/src/core/features/courses/services/handlers/dashboard-home.ts b/src/core/features/courses/services/handlers/dashboard-home.ts index 778b1d3d2..7eff9f0c8 100644 --- a/src/core/features/courses/services/handlers/dashboard-home.ts +++ b/src/core/features/courses/services/handlers/dashboard-home.ts @@ -18,6 +18,7 @@ import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@feat import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; +import { CoreLogger } from '@singletons/logger'; import { CoreCoursesDashboard } from '../dashboard'; /** @@ -30,6 +31,11 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler name = 'CoreCoursesDashboard'; priority = 1200; + logger: CoreLogger; + + constructor() { + this.logger = CoreLogger.getInstance('CoreDashboardHomeHandlerService'); + } /** * Check if the handler is enabled on a site level. @@ -59,9 +65,17 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler const dashboardEnabled = !dashboardDisabled && dashboardConfig !== '0'; if (dashboardAvailable && dashboardEnabled && !blocksDisabled) { - const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, siteId); + try { + const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, siteId); - return CoreBlockDelegate.hasSupportedBlock(blocks.mainBlocks) || CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks); + return CoreBlockDelegate.hasSupportedBlock(blocks.mainBlocks) || + CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks); + } catch (error) { + // Error getting blocks, assume it's enabled. + this.logger.error('Error getting Dashboard blocks', error); + + return true; + } } // Dashboard is enabled but not available, we will fake blocks.