Merge pull request #3119 from dpalou/MOBILE-3855
MOBILE-3855 resource: Fix activity not found for new resourcesmain
commit
6f222fe2ab
|
@ -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,18 +326,13 @@ 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.
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchForum(sync: boolean = false, showErrors: boolean = false): Promise<void> {
|
||||
if (!this.courseId || !this.module) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue