diff --git a/src/addons/mod/forum/components/index/index.ts b/src/addons/mod/forum/components/index/index.ts index 02a14872c..3c8337d41 100644 --- a/src/addons/mod/forum/components/index/index.ts +++ b/src/addons/mod/forum/components/index/index.ts @@ -89,6 +89,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom component: AddonModForumSortOrderSelectorComponent, }; + protected fetchContentDefaultError = 'addon.mod_forum.errorgetforum'; protected syncEventName = AddonModForumSyncProvider.AUTO_SYNCED; protected syncManualObserver?: CoreEventObserver; // It will observe the sync manual event. protected replyObserver?: CoreEventObserver; @@ -325,17 +326,12 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom }), ]); } catch (error) { - if (refresh) { - CoreDomUtils.showErrorModalDefault(error, 'addon.mod_forum.errorgetforum', true); + this.fetchFailed = true; // Set to prevent infinite calls with infinite-loading. - this.fetchFailed = true; // Set to prevent infinite calls with infinite-loading. - } else { - // Get forum failed, retry without using cache since it might be a new activity. - await this.refreshContent(sync); - } + throw error; // Pass the error to the parent catch. + } finally { + this.fillContextMenu(refresh); } - - this.fillContextMenu(refresh); } private async fetchForum(sync: boolean = false, showErrors: boolean = false): Promise { diff --git a/src/core/features/course/classes/main-activity-component.ts b/src/core/features/course/classes/main-activity-component.ts index 3288f7d65..1c2621036 100644 --- a/src/core/features/course/classes/main-activity-component.ts +++ b/src/core/features/course/classes/main-activity-component.ts @@ -208,8 +208,8 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR await this.fetchContent(refresh, sync, showErrors); } catch (error) { - if (!refresh && !CoreSites.getCurrentSite()?.isOfflineDisabled()) { - // Some call failed, retry without using cache since it might be a new activity. + if (!refresh && !CoreSites.getCurrentSite()?.isOfflineDisabled() && this.isNotFoundError(error)) { + // Module not found, retry without using cache. return await this.refreshContent(sync); } diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index 24964fc75..d3c200727 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -17,6 +17,7 @@ import { AddonBlog } from '@addons/blog/services/blog'; import { AddonBlogMainMenuHandlerService } from '@addons/blog/services/handlers/mainmenu'; import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; import { Params } from '@angular/router'; +import { CoreAnyError } from '@classes/errors/error'; import { IonRefresher } from '@ionic/angular'; import { CoreApp } from '@services/app'; import { CoreNavigator } from '@services/navigator'; @@ -212,6 +213,11 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, try { await this.fetchContent(refresh); } catch (error) { + if (!refresh && !CoreSites.getCurrentSite()?.isOfflineDisabled() && this.isNotFoundError(error)) { + // Module not found, retry without using cache. + return await this.refreshContent(); + } + CoreDomUtils.showErrorModalDefault(error, this.fetchContentDefaultError, true); } finally { this.loaded = true; @@ -219,6 +225,16 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, } } + /** + * Check if an error is a "module not found" error. + * + * @param error Error. + * @return Whether the error is a "module not found" error. + */ + protected isNotFoundError(error: CoreAnyError): boolean { + return CoreTextUtils.getErrorMessageFromError(error) === Translate.instant('core.course.modulenotfound'); + } + /** * Fill the context menu options */