MOBILE-2640 errors: Display backtrace for AJAX calls

main
dpalou 2018-10-05 15:35:59 +02:00
parent 910f92e5ef
commit e7e48ee78a
2 changed files with 21 additions and 18 deletions

View File

@ -988,12 +988,17 @@ 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; let extraInfo = '';
if (typeof error == 'object') { if (typeof error == 'object') {
if (this.debugDisplay && error.debuginfo) { if (this.debugDisplay) {
// Get the debug info. Escape the HTML so it is displayed as it is in the view. // Get the debug info. Escape the HTML so it is displayed as it is in the view.
extraInfo = this.textUtils.escapeHTML(error.debuginfo); if (error.debuginfo) {
extraInfo = '<br><br>' + this.textUtils.escapeHTML(error.debuginfo);
}
if (error.backtrace) {
extraInfo += '<br><br>' + this.textUtils.replaceNewLines(this.textUtils.escapeHTML(error.backtrace), '<br>');
}
} }
// We received an object instead of a string. Search for common properties. // We received an object instead of a string. Search for common properties.
@ -1029,7 +1034,7 @@ export class CoreDomUtilsProvider {
let message = this.textUtils.decodeHTML(needsTranslate ? this.translate.instant(error) : error); let message = this.textUtils.decodeHTML(needsTranslate ? this.translate.instant(error) : error);
if (extraInfo) { if (extraInfo) {
message += '<br><br>' + extraInfo; message += extraInfo;
} }
return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime); return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime);

View File

@ -224,9 +224,9 @@ export class CoreWSProvider {
ajaxData; ajaxData;
if (typeof preSets.siteUrl == 'undefined') { if (typeof preSets.siteUrl == 'undefined') {
return rejectWithError(this.translate.instant('core.unexpectederror')); return rejectWithError(this.createFakeWSError('core.unexpectederror', true));
} else if (!this.appProvider.isOnline()) { } else if (!this.appProvider.isOnline()) {
return rejectWithError(this.translate.instant('core.networkerrormsg')); return rejectWithError(this.createFakeWSError('core.networkerrormsg', true));
} }
if (typeof preSets.responseExpected == 'undefined') { if (typeof preSets.responseExpected == 'undefined') {
@ -252,40 +252,38 @@ export class CoreWSProvider {
// Check if error. Ajax layer should always return an object (if error) or an array (if success). // Check if error. Ajax layer should always return an object (if error) or an array (if success).
if (!data || typeof data != 'object') { if (!data || typeof data != 'object') {
return rejectWithError(this.translate.instant('core.serverconnection')); return rejectWithError(this.createFakeWSError('core.serverconnection', true));
} else if (data.error) { } else if (data.error) {
return rejectWithError(data.error, data.errorcode); return rejectWithError(data.error);
} }
// Get the first response since only one request was done. // Get the first response since only one request was done.
data = data[0]; data = data[0];
if (data.error) { if (data.error) {
return rejectWithError(data.exception.message, data.exception.errorcode); return rejectWithError(data.exception);
} }
return data.data; return data.data;
}, (data) => { }, (data) => {
const available = data.status == 404 ? -1 : 0; const available = data.status == 404 ? -1 : 0;
return rejectWithError(this.translate.instant('core.serverconnection'), '', available); return rejectWithError(this.createFakeWSError('core.serverconnection', true), available);
}); });
// Convenience function to return an error. // Convenience function to return an error.
function rejectWithError(message: string, code?: string, available?: number): Promise<never> { function rejectWithError(exception: any, available?: number): Promise<never> {
if (typeof available == 'undefined') { if (typeof available == 'undefined') {
if (code) { if (exception.errorcode) {
available = code == 'invalidrecord' ? -1 : 1; available = exception.errorcode == 'invalidrecord' ? -1 : 1;
} else { } else {
available = 0; available = 0;
} }
} }
return Promise.reject({ exception.available = available;
error: message,
errorcode: code, return Promise.reject(exception);
available: available
});
} }
} }