Merge pull request #1999 from dpalou/MOBILE-3073
MOBILE-3073 login: Display debug messages when adding site
This commit is contained in:
		
						commit
						5c4872288c
					
				| @ -20,7 +20,7 @@ | ||||
|     <p *ngIf="issue"> | ||||
|         {{ 'core.login.contactyouradministratorissue' | translate:{$a: ''} }} | ||||
|     </p> | ||||
|     <p *ngIf="issue"> | ||||
|     <p *ngIf="issue" margin-bottom> | ||||
|         <core-format-text [text]="issue"></core-format-text> | ||||
|     </p> | ||||
| </ion-content> | ||||
|  | ||||
| @ -154,10 +154,14 @@ export class CoreLoginSitePage { | ||||
|      * Show an error that aims people to solve the issue. | ||||
|      * | ||||
|      * @param {string} url The URL the user was trying to connect to. | ||||
|      * @param {string} error Error to display. | ||||
|      * @param {any} error Error to display. | ||||
|      */ | ||||
|     protected showLoginIssue(url: string, error: string): void { | ||||
|         const modal = this.modalCtrl.create('CoreLoginSiteErrorPage', { siteUrl: url, issue: error }); | ||||
|     protected showLoginIssue(url: string, error: any): void { | ||||
|         const modal = this.modalCtrl.create('CoreLoginSiteErrorPage', { | ||||
|             siteUrl: url, | ||||
|             issue: this.domUtils.getErrorMessage(error) | ||||
|         }); | ||||
| 
 | ||||
|         modal.present(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -363,7 +363,7 @@ export class CoreSitesProvider { | ||||
|             return this.checkSiteWithProtocol(siteUrl, protocol).catch((error) => { | ||||
|                 // Do not continue checking if a critical error happened.
 | ||||
|                 if (error.critical) { | ||||
|                     return Promise.reject(error.error); | ||||
|                     return Promise.reject(error); | ||||
|                 } | ||||
| 
 | ||||
|                 // Retry with the other protocol.
 | ||||
| @ -371,13 +371,17 @@ export class CoreSitesProvider { | ||||
| 
 | ||||
|                 return this.checkSiteWithProtocol(siteUrl, protocol).catch((secondError) => { | ||||
|                     if (secondError.critical) { | ||||
|                         return Promise.reject(secondError.error); | ||||
|                         return Promise.reject(secondError); | ||||
|                     } | ||||
| 
 | ||||
|                     // Site doesn't exist. Return the error message.
 | ||||
|                     return Promise.reject(this.textUtils.getErrorMessageFromError(error) || | ||||
|                             this.textUtils.getErrorMessageFromError(secondError) || | ||||
|                             this.translate.instant('core.cannotconnect')); | ||||
|                     if (this.textUtils.getErrorMessageFromError(error)) { | ||||
|                         return Promise.reject(error); | ||||
|                     } else if (this.textUtils.getErrorMessageFromError(secondError)) { | ||||
|                         return Promise.reject(secondError); | ||||
|                     } else { | ||||
|                         return this.translate.instant('core.cannotconnect'); | ||||
|                     } | ||||
|                 }); | ||||
|             }); | ||||
|         } | ||||
| @ -415,8 +419,11 @@ export class CoreSitesProvider { | ||||
|                 } | ||||
| 
 | ||||
|                 // Return the error message.
 | ||||
|                 return Promise.reject(this.textUtils.getErrorMessageFromError(error) || | ||||
|                         this.textUtils.getErrorMessageFromError(secondError)); | ||||
|                 if (this.textUtils.getErrorMessageFromError(error)) { | ||||
|                     return Promise.reject(error); | ||||
|                 } else { | ||||
|                     return Promise.reject(secondError); | ||||
|                 } | ||||
|             }); | ||||
|         }).then(() => { | ||||
|             // Create a temporary site to check if local_mobile is installed.
 | ||||
| @ -456,7 +463,9 @@ export class CoreSitesProvider { | ||||
|                         // Error, check if not supported.
 | ||||
|                         if (error.available === 1) { | ||||
|                             // Service supported but an error happened. Return error.
 | ||||
|                             return Promise.reject({ error: error.error }); | ||||
|                             error.critical = true; | ||||
| 
 | ||||
|                             return Promise.reject(error); | ||||
|                         } | ||||
| 
 | ||||
|                         return data; | ||||
|  | ||||
| @ -598,6 +598,64 @@ export class CoreDomUtilsProvider { | ||||
|         return this.textUtils.decodeHTML(this.translate.instant('core.error')); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the error message from an error, including debug data if needed. | ||||
|      * | ||||
|      * @param {any} error Message to show. | ||||
|      * @param {boolean} [needsTranslate] Whether the error needs to be translated. | ||||
|      * @return {string} Error message, null if no error should be displayed. | ||||
|      */ | ||||
|     getErrorMessage(error: any, needsTranslate?: boolean): string { | ||||
|         let extraInfo = ''; | ||||
| 
 | ||||
|         if (typeof error == 'object') { | ||||
|             if (this.debugDisplay) { | ||||
|                 // Get the debug info. Escape the HTML so it is displayed as it is in the view.
 | ||||
|                 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>'); | ||||
|                 } | ||||
| 
 | ||||
|                 // tslint:disable-next-line
 | ||||
|                 console.error(error); | ||||
|             } | ||||
| 
 | ||||
|             // 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.
 | ||||
|                 return null; | ||||
|             } | ||||
| 
 | ||||
|             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.
 | ||||
|             } | ||||
| 
 | ||||
|             // Try to remove tokens from the contents.
 | ||||
|             const matches = error.match(/token"?[=|:]"?(\w*)/, ''); | ||||
|             if (matches && matches[1]) { | ||||
|                 error = error.replace(new RegExp(matches[1], 'g'), 'secret'); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (error == CoreConstants.DONT_SHOW_ERROR) { | ||||
|             // The error shouldn't be shown, stop.
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         let message = this.textUtils.decodeHTML(needsTranslate ? this.translate.instant(error) : error); | ||||
| 
 | ||||
|         if (extraInfo) { | ||||
|             message += extraInfo; | ||||
|         } | ||||
| 
 | ||||
|         return message; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Retrieve component/directive instance. | ||||
|      * Please use this function only if you cannot retrieve the instance using parent/child methods: ViewChild (or similar) | ||||
| @ -1138,51 +1196,11 @@ export class CoreDomUtilsProvider { | ||||
|      * @return {Promise<Alert>} Promise resolved with the alert modal. | ||||
|      */ | ||||
|     showErrorModal(error: any, needsTranslate?: boolean, autocloseTime?: number): Promise<Alert> { | ||||
|         let extraInfo = ''; | ||||
|         const message = this.getErrorMessage(error, needsTranslate); | ||||
| 
 | ||||
|         if (typeof error == 'object') { | ||||
|             if (this.debugDisplay) { | ||||
|                 // Get the debug info. Escape the HTML so it is displayed as it is in the view.
 | ||||
|                 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>'); | ||||
|                 } | ||||
| 
 | ||||
|                 // tslint:disable-next-line
 | ||||
|                 console.error(error); | ||||
|             } | ||||
| 
 | ||||
|             // 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.
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             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.
 | ||||
|             } | ||||
| 
 | ||||
|             // Try to remove tokens from the contents.
 | ||||
|             const matches = error.match(/token"?[=|:]"?(\w*)/, ''); | ||||
|             if (matches && matches[1]) { | ||||
|                 error = error.replace(new RegExp(matches[1], 'g'), 'secret'); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (error == CoreConstants.DONT_SHOW_ERROR) { | ||||
|             // The error shouldn't be shown, stop.
 | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         let message = this.textUtils.decodeHTML(needsTranslate ? this.translate.instant(error) : error); | ||||
| 
 | ||||
|         if (extraInfo) { | ||||
|             message += extraInfo; | ||||
|         if (message === null) { | ||||
|             // Message doesn't need to be displayed, stop.
 | ||||
|             return Promise.resolve(null); | ||||
|         } | ||||
| 
 | ||||
|         return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user