MOBILE-2061 sync: Fix errors displayed while syncing

main
dpalou 2018-10-03 08:42:05 +02:00
parent e4248a8a44
commit 15b4b6b8d1
19 changed files with 49 additions and 42 deletions

View File

@ -308,7 +308,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
}).catch((error) => {
if (error && this.utils.isWebServiceError(error)) {
// A WebService has thrown an error, this means it cannot be submitted. Discard the submission.
discardError = error.message || error.error || error.content || error.body;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error);
@ -402,7 +402,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
}).catch((error) => {
if (error && this.utils.isWebServiceError(error)) {
// The WebService has thrown an error, this means it cannot be submitted. Discard the offline data.
discardError = error.message || error.error || error.content || error.body;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error);

View File

@ -176,7 +176,7 @@ export class AddonModChoiceSyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: data.name,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
}

View File

@ -295,10 +295,10 @@ export class AddonModDataSyncProvider extends CoreSyncBaseProvider {
promises.push(actionPromise.catch((error) => {
if (error && error.wserror) {
// The WebService has thrown an error, this means it cannot be performed. Discard.
discardError = error.error;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error && error.error);
return Promise.reject(error);
}
}).then(() => {
// Delete the offline data.

View File

@ -251,12 +251,12 @@ export class AddonModFeedbackSyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: feedback.name,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
} else {
// Couldn't connect to server, reject.
return Promise.reject(error && error.error);
return Promise.reject(error);
}
});
}

View File

@ -227,7 +227,7 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: data.name,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
} else {
@ -399,7 +399,7 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: data.name,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
} else {

View File

@ -198,7 +198,7 @@ export class AddonModGlossarySyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: data.concept,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
} else {

View File

@ -401,7 +401,7 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: lesson.name,
error: error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
} else {
@ -485,7 +485,7 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: lesson.name,
error: error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
} else {

View File

@ -173,13 +173,13 @@ export class AddonModSurveySyncProvider extends CoreSyncBaseProvider {
result.warnings.push(this.translate.instant('core.warningofflinedatadeleted', {
component: this.componentTranslate,
name: data.name,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
}
// Couldn't connect to server, reject.
return Promise.reject(error && error.error);
return Promise.reject(error);
});
}).then(() => {
if (courseId) {

View File

@ -291,7 +291,7 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider {
const warning = this.translate.instant('core.warningofflinedatadeleted', {
component: this.translate.instant('addon.mod_wiki.wikipage'),
name: page.title,
error: error
error: this.textUtils.getErrorMessageFromError(error)
});
result.discarded.push({

View File

@ -340,7 +340,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider {
}).catch((error) => {
if (error && this.utils.isWebServiceError(error)) {
// The WebService has thrown an error, this means it cannot be performed. Discard.
discardError = error.message || error.error;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error);
@ -421,7 +421,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider {
}).catch((error) => {
if (error && this.utils.isWebServiceError(error)) {
// The WebService has thrown an error, this means it cannot be performed. Discard.
discardError = error.message || error.error;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error);
@ -480,10 +480,10 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider {
evaluate.gradeover, siteId).catch((error) => {
if (error && this.utils.isWebServiceError(error)) {
// The WebService has thrown an error, this means it cannot be performed. Discard.
discardError = error.message || error.error;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error && error.error);
return Promise.reject(error);
}
}).then(() => {
// Delete the offline data.
@ -539,10 +539,10 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider {
evaluate.gradinggradeover, siteId).catch((error) => {
if (error && this.utils.isWebServiceError(error)) {
// The WebService has thrown an error, this means it cannot be performed. Discard.
discardError = error.message || error.error;
discardError = this.textUtils.getErrorMessageFromError(error);
} else {
// Couldn't connect to server, reject.
return Promise.reject(error && error.error);
return Promise.reject(error);
}
}).then(() => {
// Delete the offline data.

View File

@ -145,7 +145,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider {
// Responses deleted, add a warning.
result.warnings.push(this.translate.instant('core.course.warningofflinemanualcompletiondeleted', {
name: entry.coursename || courseId,
error: error.error
error: this.textUtils.getErrorMessageFromError(error)
}));
});
}

View File

@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
@ -34,7 +35,8 @@ export class CoreCoursesCourseLinkHandler extends CoreContentLinksHandlerBase {
constructor(private sitesProvider: CoreSitesProvider, private coursesProvider: CoreCoursesProvider,
private loginHelper: CoreLoginHelperProvider, private domUtils: CoreDomUtilsProvider,
private translate: TranslateService, private courseProvider: CoreCourseProvider) {
private translate: TranslateService, private courseProvider: CoreCourseProvider,
private textUtils: CoreTextUtilsProvider) {
super();
}
@ -150,7 +152,7 @@ export class CoreCoursesCourseLinkHandler extends CoreContentLinksHandlerBase {
modal.dismiss();
if (error) {
error = error.message || error.error || error.content || error.body || error;
error = this.textUtils.getErrorMessageFromError(error) || error;
}
if (!error) {
error = this.translate.instant('core.courses.notenroled');
@ -232,7 +234,7 @@ export class CoreCoursesCourseLinkHandler extends CoreContentLinksHandlerBase {
if (typeof password != 'undefined') {
// The user attempted a password. Show an error message.
this.domUtils.showErrorModal(error.message);
this.domUtils.showErrorModal(error);
}
return this.domUtils.showPrompt(body, title, placeholder).then((password) => {

View File

@ -276,7 +276,7 @@ export class CoreLoginEmailSignupPage {
}
});
}).catch((error) => {
this.domUtils.showErrorModalDefault(error && error.error, 'core.login.usernotaddederror', true);
this.domUtils.showErrorModalDefault(error, 'core.login.usernotaddederror', true);
}).finally(() => {
modal.dismiss();
});

View File

@ -70,7 +70,7 @@ export class CoreLoginForgottenPasswordPage {
this.navCtrl.pop();
}
}).catch((error) => {
this.domUtils.showErrorModal(error.error);
this.domUtils.showErrorModal(error);
}).finally(() => {
modal.dismiss();
});

View File

@ -88,7 +88,7 @@ export class CoreLoginSitePolicyPage {
this.policyLoaded = true;
});
}).catch((error) => {
this.domUtils.showErrorModalDefault(error && error.error, 'Error getting site policy.');
this.domUtils.showErrorModalDefault(error, 'Error getting site policy.');
this.cancel();
});
}
@ -118,7 +118,7 @@ export class CoreLoginSitePolicyPage {
return this.loginHelper.goToSiteInitialPage();
});
}).catch((error) => {
this.domUtils.showErrorModalDefault(error.message, 'Error accepting site policy.');
this.domUtils.showErrorModalDefault(error, 'Error accepting site policy.');
}).finally(() => {
modal.dismiss();
});

View File

@ -1001,9 +1001,9 @@ export class CoreLoginHelperProvider {
*/
treatUserTokenError(siteUrl: string, error: any): void {
if (error.errorcode == 'forcepasswordchangenotice') {
this.openChangePassword(siteUrl, error.error || error.message || error.body || error.content);
this.openChangePassword(siteUrl, this.textUtils.getErrorMessageFromError(error));
} else if (error.errorcode == 'legacymoodleversion') {
this.showLegacyNoticeModal(error.error);
this.showLegacyNoticeModal(this.textUtils.getErrorMessageFromError(error));
} else {
this.domUtils.showErrorModal(error);
}

View File

@ -388,7 +388,7 @@ export class CoreSitesProvider {
const promise = this.http.post(siteUrl + '/login/token.php', data).timeout(CoreConstants.WS_TIMEOUT).toPromise();
return promise.catch((error) => {
return Promise.reject(error.message);
return Promise.reject(error);
}).then((data: any) => {
if (data.errorcode && (data.errorcode == 'enablewsdescription' || data.errorcode == 'requirecorrectaccess')) {
return Promise.reject({ errorcode: data.errorcode, error: data.error });

View File

@ -1005,15 +1005,10 @@ export class CoreDomUtilsProvider {
if (error.coreCanceled) {
// It's a canceled error, don't display an error.
return;
} else if (typeof error.content != 'undefined') {
error = error.content;
} else if (typeof error.body != 'undefined') {
error = error.body;
} else if (typeof error.message != 'undefined') {
error = error.message;
} else if (typeof error.error != 'undefined') {
error = error.error;
} else {
}
error = this.textUtils.getErrorMessageFromError(error);
if (!error) {
// No common properties found, just stringify it.
error = JSON.stringify(error);
extraInfo = ''; // No need to add extra info because it's already in the error.
@ -1058,7 +1053,7 @@ export class CoreDomUtilsProvider {
let errorMessage = error;
if (error && typeof error != 'string') {
errorMessage = error.message || error.error || error.content || error.body;
errorMessage = this.textUtils.getErrorMessageFromError(error);
}
return this.showErrorModal(typeof errorMessage == 'string' ? error : defaultError, needsTranslate, autocloseTime);

View File

@ -400,6 +400,16 @@ export class CoreTextUtilsProvider {
});
}
/**
* Get the error message from an error object.
*
* @param {any} error Error object.
* @return {string} Error message, undefined if not found.
*/
getErrorMessageFromError(error: any): string {
return error && (error.message || error.error || error.content || error.body);
}
/**
* Get the pluginfile URL to replace @@PLUGINFILE@@ wildcards.
*