Merge pull request #3119 from dpalou/MOBILE-3855

MOBILE-3855 resource: Fix activity not found for new resources
main
Pau Ferrer Ocaña 2022-02-16 09:51:49 +01:00 committed by GitHub
commit 6f222fe2ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 11 deletions

View File

@ -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<void> {

View File

@ -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);
}

View File

@ -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
*/