MOBILE-2640 errors: Display full WS error if enabled
parent
416e9609ba
commit
910f92e5ef
|
@ -1467,6 +1467,8 @@
|
||||||
"core.settings.cordovadeviceuuid": "local_moodlemobileapp",
|
"core.settings.cordovadeviceuuid": "local_moodlemobileapp",
|
||||||
"core.settings.cordovaversion": "local_moodlemobileapp",
|
"core.settings.cordovaversion": "local_moodlemobileapp",
|
||||||
"core.settings.currentlanguage": "moodle",
|
"core.settings.currentlanguage": "moodle",
|
||||||
|
"core.settings.debugdisplay": "admin",
|
||||||
|
"core.settings.debugdisplaydescription": "local_moodlemobileapp",
|
||||||
"core.settings.deletesitefiles": "local_moodlemobileapp",
|
"core.settings.deletesitefiles": "local_moodlemobileapp",
|
||||||
"core.settings.deletesitefilestitle": "local_moodlemobileapp",
|
"core.settings.deletesitefilestitle": "local_moodlemobileapp",
|
||||||
"core.settings.deviceinfo": "local_moodlemobileapp",
|
"core.settings.deviceinfo": "local_moodlemobileapp",
|
||||||
|
|
|
@ -30,7 +30,8 @@ export class CoreConstants {
|
||||||
static SETTINGS_RICH_TEXT_EDITOR = 'CoreSettingsRichTextEditor';
|
static SETTINGS_RICH_TEXT_EDITOR = 'CoreSettingsRichTextEditor';
|
||||||
static SETTINGS_NOTIFICATION_SOUND = 'CoreSettingsNotificationSound';
|
static SETTINGS_NOTIFICATION_SOUND = 'CoreSettingsNotificationSound';
|
||||||
static SETTINGS_SYNC_ONLY_ON_WIFI = 'CoreSettingsSyncOnlyOnWifi';
|
static SETTINGS_SYNC_ONLY_ON_WIFI = 'CoreSettingsSyncOnlyOnWifi';
|
||||||
static SETTINGS_REPORT_IN_BACKGROUND = 'CoreSettingsReportInBackground';
|
static SETTINGS_DEBUG_DISPLAY = 'CoreSettingsDebugDisplay';
|
||||||
|
static SETTINGS_REPORT_IN_BACKGROUND = 'CoreSettingsReportInBackground'; // @deprecated since 3.5.0
|
||||||
|
|
||||||
// WS constants.
|
// WS constants.
|
||||||
static WS_TIMEOUT = 30000;
|
static WS_TIMEOUT = 30000;
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
"cordovadeviceuuid": "Cordova device UUID",
|
"cordovadeviceuuid": "Cordova device UUID",
|
||||||
"cordovaversion": "Cordova version",
|
"cordovaversion": "Cordova version",
|
||||||
"currentlanguage": "Current language",
|
"currentlanguage": "Current language",
|
||||||
|
"debugdisplay": "Display debug messages",
|
||||||
|
"debugdisplaydescription": "If enabled, error modals will display more data about the error if possible.",
|
||||||
"deletesitefiles": "Are you sure that you want to delete the downloaded files from the site '{{sitename}}'?",
|
"deletesitefiles": "Are you sure that you want to delete the downloaded files from the site '{{sitename}}'?",
|
||||||
"deletesitefilestitle": "Delete site files",
|
"deletesitefilestitle": "Delete site files",
|
||||||
"deviceinfo": "Device info",
|
"deviceinfo": "Device info",
|
||||||
|
|
|
@ -17,8 +17,11 @@
|
||||||
</ion-label>
|
</ion-label>
|
||||||
<ion-toggle [(ngModel)]="richTextEditor" (ngModelChange)="richTextEditorChanged()"></ion-toggle>
|
<ion-toggle [(ngModel)]="richTextEditor" (ngModelChange)="richTextEditorChanged()"></ion-toggle>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
<ion-item text-wrap *ngIf="showReport">
|
<ion-item text-wrap>
|
||||||
<ion-label><h2>{{ 'core.settings.reportinbackground' | translate }}</h2></ion-label>
|
<ion-label>
|
||||||
<ion-toggle [(ngModel)]="reportInBackground" (ngModelChange)="reportInBackgroundChanged()"></ion-toggle>
|
<h2>{{ 'core.settings.debugdisplay' | translate }}</h2>
|
||||||
|
<p>{{ 'core.settings.debugdisplaydescription' | translate }}</p>
|
||||||
|
</ion-label>
|
||||||
|
<ion-toggle [(ngModel)]="debugDisplay" (ngModelChange)="debugDisplayChanged()"></ion-toggle>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -39,8 +39,7 @@ export class CoreSettingsGeneralPage {
|
||||||
selectedLanguage: string;
|
selectedLanguage: string;
|
||||||
rteSupported: boolean;
|
rteSupported: boolean;
|
||||||
richTextEditor: boolean;
|
richTextEditor: boolean;
|
||||||
showReport: boolean;
|
debugDisplay: boolean;
|
||||||
reportInBackground: boolean;
|
|
||||||
|
|
||||||
constructor(appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, fileProvider: CoreFileProvider,
|
constructor(appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, fileProvider: CoreFileProvider,
|
||||||
private eventsProvider: CoreEventsProvider, private langProvider: CoreLangProvider,
|
private eventsProvider: CoreEventsProvider, private langProvider: CoreLangProvider,
|
||||||
|
@ -60,12 +59,9 @@ export class CoreSettingsGeneralPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localStorage && localStorage.getItem && localStorage.setItem) {
|
this.configProvider.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false).then((debugDisplay) => {
|
||||||
this.showReport = true;
|
this.debugDisplay = !!debugDisplay;
|
||||||
this.reportInBackground = parseInt(localStorage.getItem(CoreConstants.SETTINGS_REPORT_IN_BACKGROUND), 10) === 1;
|
});
|
||||||
} else {
|
|
||||||
this.showReport = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,9 +81,10 @@ export class CoreSettingsGeneralPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the report in background setting is enabled or disabled.
|
* Called when the debug display setting is enabled or disabled.
|
||||||
*/
|
*/
|
||||||
reportInBackgroundChanged(): void {
|
debugDisplayChanged(): void {
|
||||||
localStorage.setItem(CoreConstants.SETTINGS_REPORT_IN_BACKGROUND, this.reportInBackground ? '1' : '0');
|
this.configProvider.set(CoreConstants.SETTINGS_DEBUG_DISPLAY, this.debugDisplay ? 1 : 0);
|
||||||
|
this.domUtils.setDebugDisplay(this.debugDisplay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,18 @@ export class CoreDomUtilsProvider {
|
||||||
protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call.
|
protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call.
|
||||||
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
|
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
|
||||||
protected lastInstanceId = 0;
|
protected lastInstanceId = 0;
|
||||||
|
protected debugDisplay = false; // Whether to display debug messages. Store it in a variable to make it synchronous.
|
||||||
|
|
||||||
constructor(private translate: TranslateService, private loadingCtrl: LoadingController, private toastCtrl: ToastController,
|
constructor(private translate: TranslateService, private loadingCtrl: LoadingController, private toastCtrl: ToastController,
|
||||||
private alertCtrl: AlertController, private textUtils: CoreTextUtilsProvider, private appProvider: CoreAppProvider,
|
private alertCtrl: AlertController, private textUtils: CoreTextUtilsProvider, private appProvider: CoreAppProvider,
|
||||||
private platform: Platform, private configProvider: CoreConfigProvider, private urlUtils: CoreUrlUtilsProvider,
|
private platform: Platform, private configProvider: CoreConfigProvider, private urlUtils: CoreUrlUtilsProvider,
|
||||||
private modalCtrl: ModalController, private sanitizer: DomSanitizer) { }
|
private modalCtrl: ModalController, private sanitizer: DomSanitizer) {
|
||||||
|
|
||||||
|
// Check if debug messages should be displayed.
|
||||||
|
configProvider.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false).then((debugDisplay) => {
|
||||||
|
this.debugDisplay = !!debugDisplay;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Equivalent to element.closest(). If the browser doesn't support element.closest, it will
|
* Equivalent to element.closest(). If the browser doesn't support element.closest, it will
|
||||||
|
@ -841,6 +848,15 @@ export class CoreDomUtilsProvider {
|
||||||
return this.scrollToElementBySelector(content, '.core-input-error', scrollParentClass);
|
return this.scrollToElementBySelector(content, '.core-input-error', scrollParentClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether debug messages should be displayed.
|
||||||
|
*
|
||||||
|
* @param {boolean} value Whether to display or not.
|
||||||
|
*/
|
||||||
|
setDebugDisplay(value: boolean): void {
|
||||||
|
this.debugDisplay = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show an alert modal with a button to close it.
|
* Show an alert modal with a button to close it.
|
||||||
*
|
*
|
||||||
|
@ -972,7 +988,14 @@ export class CoreDomUtilsProvider {
|
||||||
* @return {Promise<Alert>} Promise resolved with the alert modal.
|
* @return {Promise<Alert>} Promise resolved with the alert modal.
|
||||||
*/
|
*/
|
||||||
showErrorModal(error: any, needsTranslate?: boolean, autocloseTime?: number): Promise<Alert> {
|
showErrorModal(error: any, needsTranslate?: boolean, autocloseTime?: number): Promise<Alert> {
|
||||||
|
let extraInfo;
|
||||||
|
|
||||||
if (typeof error == 'object') {
|
if (typeof error == 'object') {
|
||||||
|
if (this.debugDisplay && error.debuginfo) {
|
||||||
|
// Get the debug info. Escape the HTML so it is displayed as it is in the view.
|
||||||
|
extraInfo = this.textUtils.escapeHTML(error.debuginfo);
|
||||||
|
}
|
||||||
|
|
||||||
// We received an object instead of a string. Search for common properties.
|
// We received an object instead of a string. Search for common properties.
|
||||||
if (error.coreCanceled) {
|
if (error.coreCanceled) {
|
||||||
// It's a canceled error, don't display an error.
|
// It's a canceled error, don't display an error.
|
||||||
|
@ -988,6 +1011,7 @@ export class CoreDomUtilsProvider {
|
||||||
} else {
|
} else {
|
||||||
// No common properties found, just stringify it.
|
// No common properties found, just stringify it.
|
||||||
error = JSON.stringify(error);
|
error = JSON.stringify(error);
|
||||||
|
extraInfo = ''; // No need to add extra info because it's already in the error.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to remove tokens from the contents.
|
// Try to remove tokens from the contents.
|
||||||
|
@ -1002,7 +1026,11 @@ export class CoreDomUtilsProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = this.textUtils.decodeHTML(needsTranslate ? this.translate.instant(error) : error);
|
let message = this.textUtils.decodeHTML(needsTranslate ? this.translate.instant(error) : error);
|
||||||
|
|
||||||
|
if (extraInfo) {
|
||||||
|
message += '<br><br>' + extraInfo;
|
||||||
|
}
|
||||||
|
|
||||||
return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime);
|
return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime);
|
||||||
}
|
}
|
||||||
|
@ -1022,13 +1050,13 @@ export class CoreDomUtilsProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let errorMessage = error;
|
||||||
|
|
||||||
if (error && typeof error != 'string') {
|
if (error && typeof error != 'string') {
|
||||||
error = error.message || error.error || error.content || error.body;
|
errorMessage = error.message || error.error || error.content || error.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = typeof error == 'string' ? error : defaultError;
|
return this.showErrorModal(typeof errorMessage == 'string' ? error : defaultError, needsTranslate, autocloseTime);
|
||||||
|
|
||||||
return this.showErrorModal(error, needsTranslate, autocloseTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue