MOBILE-2640 errors: Display full WS error if enabled
This commit is contained in:
		
							parent
							
								
									416e9609ba
								
							
						
					
					
						commit
						910f92e5ef
					
				@ -1467,6 +1467,8 @@
 | 
			
		||||
  "core.settings.cordovadeviceuuid": "local_moodlemobileapp",
 | 
			
		||||
  "core.settings.cordovaversion": "local_moodlemobileapp",
 | 
			
		||||
  "core.settings.currentlanguage": "moodle",
 | 
			
		||||
  "core.settings.debugdisplay": "admin",
 | 
			
		||||
  "core.settings.debugdisplaydescription": "local_moodlemobileapp",
 | 
			
		||||
  "core.settings.deletesitefiles": "local_moodlemobileapp",
 | 
			
		||||
  "core.settings.deletesitefilestitle": "local_moodlemobileapp",
 | 
			
		||||
  "core.settings.deviceinfo": "local_moodlemobileapp",
 | 
			
		||||
 | 
			
		||||
@ -30,7 +30,8 @@ export class CoreConstants {
 | 
			
		||||
    static SETTINGS_RICH_TEXT_EDITOR = 'CoreSettingsRichTextEditor';
 | 
			
		||||
    static SETTINGS_NOTIFICATION_SOUND = 'CoreSettingsNotificationSound';
 | 
			
		||||
    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.
 | 
			
		||||
    static WS_TIMEOUT = 30000;
 | 
			
		||||
 | 
			
		||||
@ -10,6 +10,8 @@
 | 
			
		||||
    "cordovadeviceuuid": "Cordova device UUID",
 | 
			
		||||
    "cordovaversion": "Cordova version",
 | 
			
		||||
    "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}}'?",
 | 
			
		||||
    "deletesitefilestitle": "Delete site files",
 | 
			
		||||
    "deviceinfo": "Device info",
 | 
			
		||||
 | 
			
		||||
@ -17,8 +17,11 @@
 | 
			
		||||
        </ion-label>
 | 
			
		||||
        <ion-toggle [(ngModel)]="richTextEditor" (ngModelChange)="richTextEditorChanged()"></ion-toggle>
 | 
			
		||||
    </ion-item>
 | 
			
		||||
    <ion-item text-wrap *ngIf="showReport">
 | 
			
		||||
        <ion-label><h2>{{ 'core.settings.reportinbackground' | translate }}</h2></ion-label>
 | 
			
		||||
        <ion-toggle [(ngModel)]="reportInBackground" (ngModelChange)="reportInBackgroundChanged()"></ion-toggle>
 | 
			
		||||
    <ion-item text-wrap>
 | 
			
		||||
        <ion-label>
 | 
			
		||||
            <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-content>
 | 
			
		||||
 | 
			
		||||
@ -39,8 +39,7 @@ export class CoreSettingsGeneralPage {
 | 
			
		||||
    selectedLanguage: string;
 | 
			
		||||
    rteSupported: boolean;
 | 
			
		||||
    richTextEditor: boolean;
 | 
			
		||||
    showReport: boolean;
 | 
			
		||||
    reportInBackground: boolean;
 | 
			
		||||
    debugDisplay: boolean;
 | 
			
		||||
 | 
			
		||||
    constructor(appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, fileProvider: CoreFileProvider,
 | 
			
		||||
            private eventsProvider: CoreEventsProvider, private langProvider: CoreLangProvider,
 | 
			
		||||
@ -60,12 +59,9 @@ export class CoreSettingsGeneralPage {
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (localStorage && localStorage.getItem && localStorage.setItem) {
 | 
			
		||||
            this.showReport = true;
 | 
			
		||||
            this.reportInBackground = parseInt(localStorage.getItem(CoreConstants.SETTINGS_REPORT_IN_BACKGROUND), 10) === 1;
 | 
			
		||||
        } else {
 | 
			
		||||
            this.showReport = false;
 | 
			
		||||
        }
 | 
			
		||||
        this.configProvider.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false).then((debugDisplay) => {
 | 
			
		||||
            this.debugDisplay = !!debugDisplay;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -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 {
 | 
			
		||||
        localStorage.setItem(CoreConstants.SETTINGS_REPORT_IN_BACKGROUND, this.reportInBackground ? '1' : '0');
 | 
			
		||||
    debugDisplayChanged(): void {
 | 
			
		||||
        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 instances: {[id: string]: any} = {}; // Store component/directive instances by id.
 | 
			
		||||
    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,
 | 
			
		||||
            private alertCtrl: AlertController, private textUtils: CoreTextUtilsProvider, private appProvider: CoreAppProvider,
 | 
			
		||||
            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
 | 
			
		||||
@ -841,6 +848,15 @@ export class CoreDomUtilsProvider {
 | 
			
		||||
        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.
 | 
			
		||||
     *
 | 
			
		||||
@ -972,7 +988,14 @@ export class CoreDomUtilsProvider {
 | 
			
		||||
     * @return {Promise<Alert>} Promise resolved with the alert modal.
 | 
			
		||||
     */
 | 
			
		||||
    showErrorModal(error: any, needsTranslate?: boolean, autocloseTime?: number): Promise<Alert> {
 | 
			
		||||
        let extraInfo;
 | 
			
		||||
 | 
			
		||||
        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.
 | 
			
		||||
            if (error.coreCanceled) {
 | 
			
		||||
                // It's a canceled error, don't display an error.
 | 
			
		||||
@ -988,6 +1011,7 @@ export class CoreDomUtilsProvider {
 | 
			
		||||
            } else {
 | 
			
		||||
                // 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.
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Try to remove tokens from the contents.
 | 
			
		||||
@ -1002,7 +1026,11 @@ export class CoreDomUtilsProvider {
 | 
			
		||||
            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);
 | 
			
		||||
    }
 | 
			
		||||
@ -1022,13 +1050,13 @@ export class CoreDomUtilsProvider {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let errorMessage = error;
 | 
			
		||||
 | 
			
		||||
        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(error, needsTranslate, autocloseTime);
 | 
			
		||||
        return this.showErrorModal(typeof errorMessage == 'string' ? error : defaultError, needsTranslate, autocloseTime);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user