MOBILE-4653 utils: Move error related utils functions
parent
7ea188af49
commit
94b0266794
|
@ -41,7 +41,7 @@ import { CoreNetwork } from '@services/network';
|
|||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreSync } from '@services/sync';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreForms } from '@singletons/form';
|
||||
|
@ -258,7 +258,7 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr
|
|||
|
||||
return selectedEntry;
|
||||
} catch (error) {
|
||||
if (!params.filters || CoreUtils.isWebServiceError(error)) {
|
||||
if (!params.filters || CoreWSError.isWebServiceError(error)) {
|
||||
// Cannot get the entry, reject.
|
||||
throw error;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr
|
|||
|
||||
return await this.saveEntry({ attachmentsId: attachmentsid });
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
CoreDomUtils.showErrorModalDefault(error, 'Error updating entry.');
|
||||
|
||||
|
@ -361,7 +361,7 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr
|
|||
const attachmentsId = await this.uploadOrStoreFiles({ created });
|
||||
await this.saveEntry({ created, attachmentsId });
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
CoreDomUtils.showErrorModalDefault(error, 'Error creating entry.');
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync';
|
|||
import { CoreFileUploader } from '@features/fileuploader/services/fileuploader';
|
||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { ADDON_BLOG_AUTO_SYNCED, ADDON_BLOG_SYNC_ID } from '../constants';
|
||||
|
@ -129,7 +129,7 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
|
|||
await AddonBlogOffline.deleteOfflineEntryRecord({ created: entry.created }, siteId);
|
||||
result.updated = true;
|
||||
} catch (error) {
|
||||
if (!error || !CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ import { AddonBlogOfflineEntryDBRecord } from './database/blog';
|
|||
entriesToSync = entriesPendingToSync;
|
||||
}
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWar
|
|||
import { makeSingleton } from '@singletons';
|
||||
import { AddonBlogOffline, AddonBlogOfflineEntry } from './blog-offline';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
const ROOT_CACHE_KEY = 'addonBlog:';
|
||||
|
||||
|
@ -121,7 +122,7 @@ export class AddonBlogProvider {
|
|||
try {
|
||||
await this.addEntryOnline(params, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return await storeOffline();
|
||||
}
|
||||
|
@ -177,7 +178,7 @@ export class AddonBlogProvider {
|
|||
try {
|
||||
await this.updateEntryOnline(params, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return await storeOffline();
|
||||
}
|
||||
|
@ -232,7 +233,7 @@ export class AddonBlogProvider {
|
|||
await this.deleteEntryOnline(params, siteId);
|
||||
await CorePromiseUtils.ignoreErrors(AddonBlogOffline.unmarkEntryAsRemoved(params.entryid));
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return await AddonBlogOffline.markEntryAsRemoved({ id: params.entryid, subject }, siteId);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import {
|
|||
ADDON_CALENDAR_SYNC_ID,
|
||||
} from '../constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Service to sync calendar.
|
||||
|
@ -219,7 +220,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
|
|||
await Promise.all(promises);
|
||||
} catch (error) {
|
||||
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Local error, reject.
|
||||
throw error;
|
||||
}
|
||||
|
@ -284,7 +285,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
|
|||
return AddonCalendarOffline.deleteEvent(event.id, siteId);
|
||||
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Local error, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ export class AddonCalendarProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error && !CoreUtils.isWebServiceError(error)) {
|
||||
if (error && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
@ -1540,7 +1540,7 @@ export class AddonCalendarProvider {
|
|||
|
||||
return ({ sent: true, event });
|
||||
} catch (error) {
|
||||
if (error && !CoreUtils.isWebServiceError(error)) {
|
||||
if (error && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { CoreLogger } from '@singletons/logger';
|
||||
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreCourseAnyCourseData, CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
||||
|
@ -284,7 +284,7 @@ export class AddonCourseCompletionProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WS returned an error, plugin is not enabled.
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
AddonMessagesGetMessagesWSParams,
|
||||
} from './messages';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
|
@ -238,7 +238,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
|
|||
await AddonMessages.sendMessageOnline(userId, text, siteId);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Error sending, stop execution.
|
||||
if (CoreNetwork.isOnline()) {
|
||||
// App is online, unmark deviceoffline if marked.
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
AddonMessagesOfflineConversationMessagesDBRecordFormatted,
|
||||
AddonMessagesOfflineMessagesDBRecordFormatted,
|
||||
} from './messages-offline';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreTimeUtils } from '@services/utils/time';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
|
@ -2531,7 +2530,7 @@ export class AddonMessagesProvider {
|
|||
message: result,
|
||||
};
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
@ -2662,7 +2661,7 @@ export class AddonMessagesProvider {
|
|||
message: result,
|
||||
};
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import {
|
|||
import { AddonModAssignHelper } from '../../services/assign-helper';
|
||||
import { AddonModAssignOffline } from '../../services/assign-offline';
|
||||
import { AddonModAssignSync } from '../../services/assign-sync';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreWSExternalFile } from '@services/ws';
|
||||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||
import {
|
||||
|
@ -344,7 +344,7 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy, CanLeave {
|
|||
this.hasOffline,
|
||||
);
|
||||
} catch (error) {
|
||||
if (this.allowOffline && !this.saveOffline && !CoreUtils.isWebServiceError(error)) {
|
||||
if (this.allowOffline && !this.saveOffline && !CoreWSError.isWebServiceError(error)) {
|
||||
// Cannot submit in online, prepare for offline usage.
|
||||
this.saveOffline = true;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import {
|
|||
} from './assign-offline';
|
||||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreNetworkError } from '@classes/errors/network-error';
|
||||
import { CoreGradesFormattedItem, CoreGradesHelper } from '@features/grades/services/grades-helper';
|
||||
|
@ -360,7 +360,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
|
|||
// Submission data sent, update cached data. No need to block the user for this.
|
||||
AddonModAssign.getSubmissionStatus(assign.id, options);
|
||||
} catch (error) {
|
||||
if (!error || !CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Local error, reject.
|
||||
throw error;
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
|
|||
|
||||
await CorePromiseUtils.allPromises(promises);
|
||||
} catch (error) {
|
||||
if (!error || !CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Local error, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import { CoreTimeUtils } from '@services/utils/time';
|
|||
import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { AddonModAssignOffline } from './assign-offline';
|
||||
import { AddonModAssignSubmissionDelegate } from './submission-delegate';
|
||||
import { CoreComments } from '@features/comments/services/comments';
|
||||
|
@ -1020,7 +1019,7 @@ export class AddonModAssignProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (allowOffline && error && !CoreUtils.isWebServiceError(error)) {
|
||||
if (allowOffline && error && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
@ -1130,7 +1129,7 @@ export class AddonModAssignProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error && !CoreUtils.isWebServiceError(error)) {
|
||||
if (error && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
@ -1238,7 +1237,7 @@ export class AddonModAssignProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error && !CoreUtils.isWebServiceError(error)) {
|
||||
if (error && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
@ -1379,7 +1378,7 @@ export class AddonModAssignProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error && !CoreUtils.isWebServiceError(error)) {
|
||||
if (error && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CoreCourse } from '@features/course/services/course';
|
|||
import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonModChoice } from './choice';
|
||||
|
@ -195,7 +195,7 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid
|
|||
|
||||
await AddonModChoiceOffline.deleteResponse(choiceId, siteId, userId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { AddonModChoiceOffline } from './choice-offline';
|
||||
|
@ -121,7 +120,7 @@ export class AddonModChoiceProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
@ -434,7 +433,7 @@ export class AddonModChoiceProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import { CoreTime } from '@singletons/time';
|
|||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||
import { ADDON_MOD_DATA_COMPONENT, ADDON_MOD_DATA_ENTRY_CHANGED, AddonModDataTemplateType } from '../../constants';
|
||||
import { CoreLoadings } from '@services/loadings';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Page that displays the view edit page.
|
||||
|
@ -303,7 +304,7 @@ export class AddonModDataEditPage implements OnInit {
|
|||
this.offline,
|
||||
);
|
||||
} catch (error) {
|
||||
if (this.offline || CoreUtils.isWebServiceError(error)) {
|
||||
if (this.offline || CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
|
|||
import { ADDON_MOD_DATA_AUTO_SYNCED, ADDON_MOD_DATA_COMPONENT, AddonModDataAction } from '../constants';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Service to sync databases.
|
||||
|
@ -294,7 +295,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
|||
|
||||
timemodified = entry.entry.timemodified;
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means the entry has been deleted.
|
||||
timemodified = -1;
|
||||
} else {
|
||||
|
@ -326,7 +327,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
|||
await AddonModData.deleteEntryOnline(entryId, siteId);
|
||||
entryResult.deleted = true;
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
entryResult.discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
} else {
|
||||
|
@ -384,7 +385,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
|||
await AddonModData.editEntryOnline(entryId, editAction.fields, siteId);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
entryResult.discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
} else {
|
||||
|
@ -402,7 +403,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
|||
try {
|
||||
await AddonModData.approveEntryOnline(entryId, approveAction.action == AddonModDataAction.APPROVE, siteId);
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
entryResult.discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
} else {
|
||||
|
|
|
@ -36,6 +36,7 @@ import {
|
|||
} from '../constants';
|
||||
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
declare module '@singletons/events' {
|
||||
|
||||
|
@ -124,7 +125,7 @@ export class AddonModDataProvider {
|
|||
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
@ -213,7 +214,7 @@ export class AddonModDataProvider {
|
|||
sent: true,
|
||||
};
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
@ -308,7 +309,7 @@ export class AddonModDataProvider {
|
|||
try {
|
||||
await this.deleteEntryOnline(entryId, siteId);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
@ -424,7 +425,7 @@ export class AddonModDataProvider {
|
|||
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import {
|
|||
import { CoreLoadings } from '@services/loadings';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Page that displays feedback form.
|
||||
|
@ -219,7 +220,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
|
|||
try {
|
||||
this.access = await AddonModFeedback.getFeedbackAccessInformation(this.feedback.id, options);
|
||||
} catch (error) {
|
||||
if (this.offline || CoreUtils.isWebServiceError(error)) {
|
||||
if (this.offline || CoreWSError.isWebServiceError(error)) {
|
||||
// Already offline or shouldn't go offline, fail.
|
||||
throw error;
|
||||
}
|
||||
|
@ -246,7 +247,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
|
|||
try {
|
||||
return await AddonModFeedback.getResumePage(this.feedback.id, options);
|
||||
} catch (error) {
|
||||
if (this.offline || CoreUtils.isWebServiceError(error)) {
|
||||
if (this.offline || CoreWSError.isWebServiceError(error)) {
|
||||
// Already offline or shouldn't go offline, fail.
|
||||
throw error;
|
||||
}
|
||||
|
@ -314,7 +315,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
|
|||
try {
|
||||
response = await AddonModFeedback.getPageItemsWithValues(this.feedback.id, page, options);
|
||||
} catch (error) {
|
||||
if (this.offline || CoreUtils.isWebServiceError(error)) {
|
||||
if (this.offline || CoreWSError.isWebServiceError(error)) {
|
||||
// Already offline or shouldn't go offline, fail.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonModFeedback, AddonModFeedbackWSFeedback } from './feedback';
|
||||
|
@ -266,7 +266,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv
|
|||
|
||||
await AddonModFeedbackOffline.deleteFeedbackPageResponses(feedback.id, data.page, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import {
|
|||
} from '../constants';
|
||||
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Service that provides some features for feedbacks.
|
||||
|
@ -1195,7 +1196,7 @@ export class AddonModFeedbackProvider {
|
|||
try {
|
||||
return await this.processPageOnline(feedbackId, page, responses, !!options.goPrevious, options.siteId);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import { Params } from '@angular/router';
|
|||
import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source';
|
||||
import { CoreUser } from '@features/user/services/user';
|
||||
import { CoreGroupInfo, CoreGroups } from '@services/groups';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import {
|
||||
AddonModForum,
|
||||
AddonModForumCanAddDiscussion,
|
||||
|
@ -246,7 +246,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource
|
|||
canLoadMore = response.canLoadMore;
|
||||
this.errorLoadingDiscussions = false;
|
||||
} catch (error) {
|
||||
if (page > 0 || CoreUtils.isWebServiceError(error)) {
|
||||
if (page > 0 || CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ import { CorePopovers } from '@services/popovers';
|
|||
import { CoreLoadings } from '@services/loadings';
|
||||
import { CoreWSFile } from '@services/ws';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Components that shows a discussion post, its attachments and the action buttons allowed (reply, etc.).
|
||||
|
@ -554,7 +555,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
|||
return { attachments, saveOffline: false };
|
||||
} catch (error) {
|
||||
// Cannot upload them in online, save them in offline.
|
||||
if (!this.forum.id || CoreUtils.isWebServiceError(error)) {
|
||||
if (!this.forum.id || CoreWSError.isWebServiceError(error)) {
|
||||
// Cannot store them in offline. Reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import { AddonModForumDiscussionOptions, AddonModForumOffline, AddonModForumOffl
|
|||
import { CoreFileEntry } from '@services/file-helper';
|
||||
import { ADDON_MOD_FORUM_ALL_GROUPS, ADDON_MOD_FORUM_COMPONENT } from '../constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Service that provides some features for forums.
|
||||
|
@ -107,7 +108,7 @@ export class AddonModForumHelperProvider {
|
|||
try {
|
||||
await Promise.all(promises);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
@ -161,7 +162,7 @@ export class AddonModForumHelperProvider {
|
|||
if (errors.length == groupIds.length) {
|
||||
// All requests have failed.
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
if (CoreUtils.isWebServiceError(errors[i]) || (attachments && attachments.length > 0)) {
|
||||
if (CoreWSError.isWebServiceError(errors[i]) || (attachments && attachments.length > 0)) {
|
||||
// The WebService has thrown an error or offline not supported, reject.
|
||||
throw errors[i];
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import {
|
|||
ADDON_MOD_FORUM_MANUAL_SYNCED,
|
||||
} from '../constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
declare module '@singletons/events' {
|
||||
|
||||
|
@ -273,7 +274,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide
|
|||
if (errors.length === groupIds.length) {
|
||||
// All requests have failed, reject if errors were not returned by WS.
|
||||
for (const error of errors) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
@ -490,7 +491,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide
|
|||
|
||||
await this.deleteReply(forumId, reply.postid, siteId, userId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ import {
|
|||
} from '../constants';
|
||||
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
declare module '@singletons/events' {
|
||||
|
||||
|
@ -1113,7 +1114,7 @@ export class AddonModForumProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (allowOffline && !CoreUtils.isWebServiceError(error)) {
|
||||
if (allowOffline && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ import { CoreNetwork } from '@services/network';
|
|||
import { CoreSites } from '@services/sites';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { Translate } from '@singletons';
|
||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||
import { CoreForms } from '@singletons/form';
|
||||
|
@ -522,7 +522,7 @@ class AddonModGlossaryNewFormHandler extends AddonModGlossaryFormHandler {
|
|||
try {
|
||||
onlineAttachments = await this.uploadAttachments(glossary);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import { CoreRatingSync } from '@features/rating/services/rating-sync';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonModGlossary } from './glossary';
|
||||
|
@ -207,7 +207,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv
|
|||
|
||||
await this.deleteAddEntry(glossaryId, data.concept, data.timecreated, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import {
|
|||
} from '../constants';
|
||||
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Service that provides some features for glossaries.
|
||||
|
@ -874,7 +875,7 @@ export class AddonModGlossaryProvider {
|
|||
|
||||
return entryId;
|
||||
} catch (error) {
|
||||
if (otherOptions.allowOffline && !CoreUtils.isWebServiceError(error)) {
|
||||
if (otherOptions.allowOffline && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import { CoreXAPIOffline } from '@features/xapi/services/offline';
|
|||
import { CoreXAPI, XAPI_STATE_DELETED } from '@features/xapi/services/xapi';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import {
|
||||
|
@ -196,7 +195,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
|
|||
h5pActivity = await AddonModH5PActivity.getH5PActivityByContextId(courseId, contextId, { siteId });
|
||||
} catch (error) {
|
||||
if (
|
||||
CoreUtils.isWebServiceError(error) ||
|
||||
CoreWSError.isWebServiceError(error) ||
|
||||
CoreErrorHelper.getErrorMessageFromError(error) === Translate.instant('core.course.modulenotfound')
|
||||
) {
|
||||
// Activity no longer accessible. Delete the data and finish the sync.
|
||||
|
@ -253,7 +252,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
|
|||
|
||||
await CoreXAPIOffline.deleteStatements(entry.id, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
@ -313,7 +312,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
|
|||
} catch (error) {
|
||||
// Error getting attempts. If the WS has thrown an exception it means the user cannot retrieve the attempts for
|
||||
// some reason (it shouldn't happen), continue synchronizing in that case.
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +363,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
|
|||
siteId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreWSExternalWarning, CoreWSExternalFile, CoreWSFile } from '@services/ws';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
||||
import { CoreH5P } from '@features/h5p/services/h5p';
|
||||
|
@ -380,7 +379,7 @@ export class AddonModH5PActivityProvider {
|
|||
|
||||
return this.formatAttemptResults(response.attempts[0]);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
@ -634,7 +633,7 @@ export class AddonModH5PActivityProvider {
|
|||
|
||||
return this.formatUserAttempts(response.usersattempts[0]);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
|||
import { ADDON_MOD_LESSON_COMPONENT, AddonModLessonJumpTo } from '../../constants';
|
||||
import { CoreModals } from '@services/modals';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Page that allows attempting and reviewing a lesson.
|
||||
|
@ -214,7 +215,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
|
|||
throw error;
|
||||
}
|
||||
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// WebService returned an error, cannot perform the action.
|
||||
throw error;
|
||||
}
|
||||
|
@ -356,7 +357,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
|
|||
return true;
|
||||
} catch (error) {
|
||||
|
||||
if (this.review && this.retakeToReview && CoreUtils.isWebServiceError(error)) {
|
||||
if (this.review && this.retakeToReview && CoreWSError.isWebServiceError(error)) {
|
||||
// The user cannot review the retake. Unmark the retake as being finished in sync.
|
||||
await AddonModLessonSync.deleteRetakeFinishedInSync(this.lesson!.id);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CoreNavigator } from '@services/navigator';
|
|||
import { CoreSites } from '@services/sites';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { Translate } from '@singletons';
|
||||
import {
|
||||
AddonModLesson,
|
||||
|
@ -103,7 +103,7 @@ export class AddonModLessonUserRetakePage implements OnInit {
|
|||
this.performLogView();
|
||||
} catch (error) {
|
||||
this.selectedRetake = this.previousSelectedRetake ?? this.selectedRetake;
|
||||
CoreDomUtils.showErrorModal(CoreUtils.addDataNotDownloadedError(error, 'Error getting attempt.'));
|
||||
CoreDomUtils.showErrorModal(CoreErrorHelper.addDataNotDownloadedError(error, 'Error getting attempt.'));
|
||||
} finally {
|
||||
this.loaded = true;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
|||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreTimeUtils } from '@services/utils/time';
|
||||
import { CoreUrl } from '@singletons/url';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonModLessonRetakeFinishedInSyncDBRecord, RETAKES_FINISHED_SYNC_TABLE_NAME } from './database/lesson';
|
||||
|
@ -375,7 +375,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
|
|||
|
||||
await AddonModLessonOffline.deleteAttempt(lesson.id, retake, pageId, timemodified, siteId);
|
||||
} catch (error) {
|
||||
if (!error || !CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server.
|
||||
throw error;
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
|
|||
|
||||
await AddonModLessonOffline.deleteRetake(lessonId, siteId);
|
||||
} catch (error) {
|
||||
if (!error || !CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CoreCourse } from '@features/course/services/course';
|
|||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { AddonModQuizAccessRuleDelegate } from './access-rules-delegate';
|
||||
import {
|
||||
|
@ -503,7 +503,7 @@ export class AddonModQuizHelperProvider {
|
|||
|
||||
return attempt;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService returned an error, assume the preflight failed.
|
||||
AddonModQuizAccessRuleDelegate.notifyPreflightCheckFailed(
|
||||
rules,
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CoreCourse } from '@features/course/services/course';
|
|||
import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { getPrefetchHandlerInstance } from './handlers/prefetch';
|
||||
|
@ -185,7 +185,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
|
|||
// Answers sent, delete them.
|
||||
await AddonModSurveyOffline.deleteSurveyAnswers(surveyId, siteId, userId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Local error, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { AddonModSurveyOffline } from './survey-offline';
|
||||
|
@ -268,7 +268,7 @@ export class AddonModSurveyProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CoreNetwork } from '@services/network';
|
|||
import { CoreGroups } from '@services/groups';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonModWikiPageDBRecord } from './database/wiki';
|
||||
|
@ -248,7 +248,7 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider<AddonModWikiS
|
|||
// Delete the local page.
|
||||
await AddonModWikiOffline.deleteNewPage(page.title, subwikiId, wikiId, userId, groupId, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CoreTagItem } from '@features/tag/services/tag';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreWSExternalFile, CoreWSExternalWarning, CoreWSFile } from '@services/ws';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
|
@ -719,7 +719,7 @@ export class AddonModWikiProvider {
|
|||
// Try to create it in online.
|
||||
return await this.newPageOnline(title, content, options);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that the page cannot be added.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import {
|
|||
import { toBoolean } from '@/core/transforms/boolean';
|
||||
import { CoreLoadings } from '@services/loadings';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Component that displays workshop assessment strategy form.
|
||||
|
@ -318,7 +319,7 @@ export class AddonModWorkshopAssessmentStrategyComponent implements OnInit, OnDe
|
|||
saveOffline,
|
||||
);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import { CoreSites } from '@services/sites';
|
|||
import { CoreSync } from '@services/sync';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { Translate } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreForms } from '@singletons/form';
|
||||
|
@ -376,7 +376,7 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy, Ca
|
|||
false,
|
||||
);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import { CoreFileEntry } from '@services/file-helper';
|
|||
import { CoreSites } from '@services/sites';
|
||||
import { CoreSync, CoreSyncResult } from '@services/sync';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { Translate, makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonModWorkshop,
|
||||
|
@ -372,7 +372,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider<AddonModW
|
|||
await AddonModWorkshop.deleteSubmissionOnline(submissionId, siteId);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider<AddonModW
|
|||
|
||||
await AddonModWorkshop.updateAssessmentOnline(assessmentId, inputData, siteId);
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
} else {
|
||||
|
@ -544,7 +544,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider<AddonModW
|
|||
siteId,
|
||||
);
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
} else {
|
||||
|
@ -612,7 +612,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider<AddonModW
|
|||
siteId,
|
||||
);
|
||||
} catch (error) {
|
||||
if (error && CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means it cannot be performed. Discard.
|
||||
discardError = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
} else {
|
||||
|
|
|
@ -40,6 +40,7 @@ import {
|
|||
} from '@addons/mod/workshop/constants';
|
||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
declare module '@singletons/events' {
|
||||
|
||||
|
@ -708,7 +709,7 @@ export class AddonModWorkshopProvider {
|
|||
try {
|
||||
return await this.addSubmissionOnline(workshopId, title, content, attachmentsId as number, siteId);
|
||||
} catch (error) {
|
||||
if (allowOffline && !CoreUtils.isWebServiceError(error)) {
|
||||
if (allowOffline && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
}
|
||||
|
@ -808,7 +809,7 @@ export class AddonModWorkshopProvider {
|
|||
try {
|
||||
return await this.updateSubmissionOnline(submissionId, title, content, attachmentsId as number, siteId);
|
||||
} catch (error) {
|
||||
if (allowOffline && !CoreUtils.isWebServiceError(error)) {
|
||||
if (allowOffline && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
}
|
||||
|
@ -887,7 +888,7 @@ export class AddonModWorkshopProvider {
|
|||
try {
|
||||
return await this.deleteSubmissionOnline(submissionId, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
}
|
||||
|
@ -1159,7 +1160,7 @@ export class AddonModWorkshopProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (allowOffline && !CoreUtils.isWebServiceError(error)) {
|
||||
if (allowOffline && !CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
}
|
||||
|
@ -1236,7 +1237,7 @@ export class AddonModWorkshopProvider {
|
|||
try {
|
||||
return await this.evaluateSubmissionOnline(submissionId, feedbackText, published, gradeOver, siteId);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error or offline not supported, reject.
|
||||
throw error;
|
||||
}
|
||||
|
@ -1326,7 +1327,7 @@ export class AddonModWorkshopProvider {
|
|||
try {
|
||||
return await this.evaluateAssessmentOnline(assessmentId, feedbackText, weight, gradingGradeOver, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, store in offline.
|
||||
return storeOffline();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
|
|||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { Translate, makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonNotesDBRecord, AddonNotesDeletedDBRecord } from './database/notes';
|
||||
|
@ -179,7 +179,7 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider<AddonNotesSyncR
|
|||
|
||||
return;
|
||||
}).catch((error) => {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, this means the user cannot send notes.
|
||||
errors.push(error);
|
||||
|
||||
|
@ -203,7 +203,7 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider<AddonNotesSyncR
|
|||
|
||||
// Delete the notes.
|
||||
promises.push(AddonNotes.deleteNotesOnline(notesToDelete, courseId, siteId).catch((error) => {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, this means the user cannot send notes.
|
||||
errors.push(error);
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import { CoreWSError } from '@classes/errors/wserror';
|
|||
import { CoreUser } from '@features/user/services/user';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSExternalWarning } from '@services/ws';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { AddonNotesOffline } from './notes-offline';
|
||||
|
@ -70,7 +69,7 @@ export class AddonNotesProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
@ -173,7 +172,7 @@ export class AddonNotesProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the note so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { ElementController } from './ElementController';
|
||||
import { CorePromisedValue } from '@classes/promised-value';
|
||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||
|
@ -70,7 +70,7 @@ export class MediaElementController extends ElementController {
|
|||
|
||||
this.addPlaybackEventListeners(jsPlayer);
|
||||
} catch (error) {
|
||||
CoreUtils.logUnhandledError('Error enabling media element', error);
|
||||
CoreErrorHelper.logUnhandledError('Error enabling media element', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,39 @@ export class CoreWSError extends CoreError {
|
|||
this.backtrace = error.backtrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an error returned by a WS call, check if the error is generated by the app or it has been returned by the WebService.
|
||||
*
|
||||
* @param error Error to check.
|
||||
* @returns Whether the error was returned by the WebService.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
static isWebServiceError(error: any): boolean {
|
||||
return !!error && (
|
||||
error.warningcode !== undefined ||
|
||||
(
|
||||
error.errorcode !== undefined && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
||||
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
||||
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
||||
error.errorcode != 'wsaccessusersuspended' && error.errorcode != 'wsaccessuserdeleted' &&
|
||||
!this.isExpiredTokenError(error)
|
||||
) ||
|
||||
!!error.status && error.status >= 400 // CoreHttpError, assume status 400 and above are like WebService errors.
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an error returned by a WS call, check if the error is a token expired error.
|
||||
*
|
||||
* @param error Error to check.
|
||||
* @returns Whether the error is a token expired error.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
static isExpiredTokenError(error: any): boolean {
|
||||
return error.errorcode === 'invalidtoken' ||
|
||||
(error.errorcode === 'accessexception' && error.message.includes('Invalid token - token expired'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type CoreWSErrorData = {
|
||||
|
|
|
@ -642,7 +642,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite {
|
|||
} catch (error) {
|
||||
let useSilentError = false;
|
||||
|
||||
if (CoreUtils.isExpiredTokenError(error)) {
|
||||
if (CoreWSError.isExpiredTokenError(error)) {
|
||||
// Session expired, trigger event.
|
||||
this.triggerSiteEvent(CoreEvents.SESSION_EXPIRED, {});
|
||||
// Change error message. Try to get data from cache, the event will handle the error.
|
||||
|
@ -719,7 +719,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite {
|
|||
throw new CoreWSError(error);
|
||||
}
|
||||
|
||||
if (preSets.deleteCacheIfWSError && CoreUtils.isWebServiceError(error)) {
|
||||
if (preSets.deleteCacheIfWSError && CoreWSError.isWebServiceError(error)) {
|
||||
// Delete the cache entry and return the entry. Don't block the user with the delete.
|
||||
CorePromiseUtils.ignoreErrors(this.deleteFromCache(method, data, preSets));
|
||||
|
||||
|
@ -785,7 +785,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite {
|
|||
try {
|
||||
return await this.callOrEnqueueRequest<T>(method, data, preSets, wsPreSets);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isExpiredTokenError(error)) {
|
||||
if (CoreWSError.isExpiredTokenError(error)) {
|
||||
if (initialToken !== this.token) {
|
||||
// Token has changed, retry with the new token.
|
||||
wsPreSets.wsToken = this.token ?? '';
|
||||
|
|
|
@ -32,7 +32,7 @@ import { CoreSites } from '@services/sites';
|
|||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreIframeUtils, CoreIframeUtilsProvider } from '@services/utils/iframe';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { NgZone, Translate } from '@singletons';
|
||||
import { CoreExternalContentDirective } from './external-content';
|
||||
|
@ -627,7 +627,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
|
|||
}
|
||||
|
||||
// Run asynchronous operations in the background to avoid blocking rendering.
|
||||
Promise.all(promises).catch(error => CoreUtils.logUnhandledError('Error treating format-text elements', error));
|
||||
Promise.all(promises).catch(error => CoreErrorHelper.logUnhandledError('Error treating format-text elements', error));
|
||||
|
||||
return [
|
||||
...videoControllers,
|
||||
|
|
|
@ -20,7 +20,7 @@ import { makeSingleton, Translate } from '@singletons';
|
|||
import { CoreCommentsOffline } from './comments-offline';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreNetworkError } from '@classes/errors/network-error';
|
||||
import { CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments';
|
||||
import { CoreSyncResult } from '@services/sync';
|
||||
|
@ -282,7 +282,7 @@ export class CoreCommentsSyncProvider extends CoreSyncBaseProvider<CoreCommentsS
|
|||
CoreComments.getComments(contextLevel, instanceId, component, itemId, area, 0, siteId),
|
||||
);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, this means the user cannot send comments.
|
||||
errors.push(error.message);
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error';
|
|||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreWSExternalWarning } from '@services/ws';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
|
@ -105,7 +105,7 @@ export class CoreCommentsProvider {
|
|||
try {
|
||||
return await this.addCommentOnline(content, contextLevel, instanceId, component, itemId, area, siteId);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the message so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ export class CoreCommentsProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// It's a WebService error, the user cannot send the comment so don't store it.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -1327,7 +1327,7 @@ export class CoreCourseProvider {
|
|||
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
} else {
|
||||
|
|
|
@ -142,7 +142,7 @@ export class CoreCourseLogHelperProvider {
|
|||
try {
|
||||
await this.logOnline(ws, data, site.getId());
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ export class CoreCourseLogHelperProvider {
|
|||
try {
|
||||
await this.logOnline(log.ws, data, siteId);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that responses cannot be submitted.
|
||||
await CorePromiseUtils.ignoreErrors(this.deleteWSLogs(log.ws, data, siteId));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import { CoreSyncBaseProvider } from '@classes/base-sync';
|
|||
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { CoreCourseOffline } from './course-offline';
|
||||
import { CoreCourse } from './course';
|
||||
|
@ -212,7 +212,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
|
|||
|
||||
await CoreCourseOffline.deleteManualCompletion(entry.cmid, siteId);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import { CorePluginFileDownloadableResult, CorePluginFileHandler } from '@servic
|
|||
import { CoreSites } from '@services/sites';
|
||||
import { CoreMimetypeUtils } from '@services/utils/mimetype';
|
||||
import { CoreUrl } from '@singletons/url';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreWSFile } from '@services/ws';
|
||||
import { CoreH5P } from '../h5p';
|
||||
import { Translate, makeSingleton } from '@singletons';
|
||||
|
@ -103,7 +103,7 @@ export class CoreH5PPluginFileHandlerService implements CorePluginFileHandler {
|
|||
|
||||
return trustedFile.filesize || 0;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// WS returned an error, it means it cannot be downloaded.
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ import { CoreNavigator } from '@services/navigator';
|
|||
import { CoreWait } from '@singletons/wait';
|
||||
import { MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT } from '@features/mainmenu/constants';
|
||||
import { CorePromiseUtils } from '@singletons/promise-utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Service to handle push notifications.
|
||||
|
@ -578,7 +579,7 @@ export class CorePushNotificationsProvider {
|
|||
try {
|
||||
response = await site.write<CoreUserRemoveUserDeviceWSResponse>('core_user_remove_user_device', data);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error) || CoreUtils.isExpiredTokenError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error) || CoreWSError.isExpiredTokenError(error)) {
|
||||
// Cannot unregister. Don't try again.
|
||||
await CorePromiseUtils.ignoreErrors(this.pendingUnregistersTable.delete({
|
||||
token: site.getToken(),
|
||||
|
|
|
@ -19,7 +19,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
|
|||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreRating } from './rating';
|
||||
|
@ -222,7 +222,7 @@ export class CoreRatingSyncProvider extends CoreSyncBaseProvider<CoreRatingSyncI
|
|||
siteId,
|
||||
);
|
||||
} catch (error) {
|
||||
if (!CoreUtils.isWebServiceError(error)) {
|
||||
if (!CoreWSError.isWebServiceError(error)) {
|
||||
// Couldn't connect to server, reject.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import { makeSingleton } from '@singletons';
|
|||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreRatingOffline } from './rating-offline';
|
||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
const ROOT_CACHE_KEY = 'CoreRating:';
|
||||
|
||||
|
@ -128,7 +129,7 @@ export class CoreRatingProvider {
|
|||
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error or offline not supported, reject.
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreErrorHelper } from '@services/error-helper';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreSyncBaseProvider } from '@classes/base-sync';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreUserOffline } from './user-offline';
|
||||
|
@ -89,7 +89,7 @@ export class CoreUserSyncProvider extends CoreSyncBaseProvider<string[]> {
|
|||
try {
|
||||
await CoreUser.setUserPreference(preference.name, preference.value, siteId);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
const warning = CoreErrorHelper.getErrorMessageFromError(error);
|
||||
if (warning) {
|
||||
warnings.push(warning);
|
||||
|
|
|
@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
import { CoreNetwork } from '@services/network';
|
||||
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { CoreSite } from '@classes/sites/site';
|
||||
import { CoreXAPIOffline, CoreXAPIOfflineSaveStatementsOptions } from './offline';
|
||||
import { makeSingleton } from '@singletons';
|
||||
|
@ -121,7 +121,7 @@ export class CoreXAPIProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that the state cannot be deleted.
|
||||
throw error;
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ export class CoreXAPIProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that statements cannot be submitted.
|
||||
throw error;
|
||||
} else {
|
||||
|
@ -421,7 +421,7 @@ export class CoreXAPIProvider {
|
|||
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
// The WebService has thrown an error, this means that state cannot be submitted.
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
|
|||
import { CoreAnyError, CoreError } from '@classes/errors/error';
|
||||
import { makeSingleton, Translate } from '@singletons';
|
||||
import { AlertButton } from '@ionic/angular';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
|
||||
/**
|
||||
* Provider to provide some helper functions regarding files and packages.
|
||||
|
@ -23,6 +24,24 @@ import { AlertButton } from '@ionic/angular';
|
|||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreErrorHelperService {
|
||||
|
||||
/**
|
||||
* Given an error, add an extra warning to the error message and return the new error message.
|
||||
*
|
||||
* @param error Error object or message.
|
||||
* @param defaultError Message to show if the error is not a string.
|
||||
* @returns New error message.
|
||||
*/
|
||||
addDataNotDownloadedError(error: Error | string, defaultError?: string): string {
|
||||
const errorMessage = CoreErrorHelper.getErrorMessageFromError(error) || defaultError || '';
|
||||
|
||||
if (CoreWSError.isWebServiceError(error)) {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// Local error. Add an extra warning.
|
||||
return errorMessage + '<br><br>' + Translate.instant('core.errorsomedatanotdownloaded');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some text to an error message.
|
||||
*
|
||||
|
@ -158,6 +177,17 @@ export class CoreErrorHelperService {
|
|||
return element?.innerText.trim() ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an unhandled error.
|
||||
*
|
||||
* @param message Message to contextualize the error.
|
||||
* @param error Error to log.
|
||||
*/
|
||||
logUnhandledError(message: string, error: unknown): void {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Unhandled error: '+message, error);
|
||||
}
|
||||
|
||||
}
|
||||
export const CoreErrorHelper = makeSingleton(CoreErrorHelperService);
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import { CoreSiteCheckResponse, CoreSites } from './sites';
|
|||
import { CoreDomUtils } from './utils/dom';
|
||||
import { CoreErrorHelper, CoreErrorObject } from './error-helper';
|
||||
import { CoreUrl } from '@singletons/url';
|
||||
import { CoreUtils } from './utils/utils';
|
||||
import { CoreLoadings } from './loadings';
|
||||
|
||||
/*
|
||||
|
@ -494,7 +493,7 @@ export class CoreCustomURLSchemesProvider {
|
|||
treatHandleCustomURLError(error: CoreCustomURLSchemesHandleError): void {
|
||||
if (error.error == 'Duplicated') {
|
||||
// Duplicated request
|
||||
} else if (CoreUtils.isWebServiceError(error.error) && error.data && error.data.isSSOToken) {
|
||||
} else if (CoreWSError.isWebServiceError(error.error) && error.data && error.data.isSSOToken) {
|
||||
// An error occurred, display the error and logout the user.
|
||||
CoreLoginHelper.treatUserTokenError(error.data.siteUrl, <CoreWSError> error.error);
|
||||
CoreSites.logout();
|
||||
|
|
|
@ -62,16 +62,10 @@ export class CoreUtilsProvider {
|
|||
* @param error Error object or message.
|
||||
* @param defaultError Message to show if the error is not a string.
|
||||
* @returns New error message.
|
||||
* @deprecated since 5.0. Use CoreErrorHelper.addDataNotDownloadedError instead.
|
||||
*/
|
||||
addDataNotDownloadedError(error: Error | string, defaultError?: string): string {
|
||||
const errorMessage = CoreErrorHelper.getErrorMessageFromError(error) || defaultError || '';
|
||||
|
||||
if (this.isWebServiceError(error)) {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// Local error. Add an extra warning.
|
||||
return errorMessage + '<br><br>' + Translate.instant('core.errorsomedatanotdownloaded');
|
||||
return CoreErrorHelper.addDataNotDownloadedError(error, defaultError);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,9 +117,10 @@ export class CoreUtilsProvider {
|
|||
*
|
||||
* @param message Message to contextualize the error.
|
||||
* @param error Error to log.
|
||||
* @deprecated since 5.0. Use CoreErrorHelper.logUnhandledError instead.
|
||||
*/
|
||||
logUnhandledError(message: string, error: unknown): void {
|
||||
this.logger.error(message, error);
|
||||
CoreErrorHelper.logUnhandledError(message, error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -828,6 +823,7 @@ export class CoreUtilsProvider {
|
|||
*
|
||||
* @param error Error to check.
|
||||
* @returns Whether the error was returned by the WebService.
|
||||
* @deprecated since 5.0. Use CoreWSError.isWebServiceError instead.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
isWebServiceError(error: any): boolean {
|
||||
|
@ -838,6 +834,7 @@ export class CoreUtilsProvider {
|
|||
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
||||
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
||||
error.errorcode != 'wsaccessusersuspended' && error.errorcode != 'wsaccessuserdeleted' &&
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
!this.isExpiredTokenError(error)
|
||||
) ||
|
||||
error.status && error.status >= 400 // CoreHttpError, assume status 400 and above are like WebService errors.
|
||||
|
@ -849,6 +846,7 @@ export class CoreUtilsProvider {
|
|||
*
|
||||
* @param error Error to check.
|
||||
* @returns Whether the error is a token expired error.
|
||||
* @deprecated since 5.0. Use CoreWSError.isExpiredTokenError instead.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
isExpiredTokenError(error: any): boolean {
|
||||
|
|
Loading…
Reference in New Issue