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"> |     <p *ngIf="issue"> | ||||||
|         {{ 'core.login.contactyouradministratorissue' | translate:{$a: ''} }} |         {{ 'core.login.contactyouradministratorissue' | translate:{$a: ''} }} | ||||||
|     </p> |     </p> | ||||||
|     <p *ngIf="issue"> |     <p *ngIf="issue" margin-bottom> | ||||||
|         <core-format-text [text]="issue"></core-format-text> |         <core-format-text [text]="issue"></core-format-text> | ||||||
|     </p> |     </p> | ||||||
| </ion-content> | </ion-content> | ||||||
|  | |||||||
| @ -154,10 +154,14 @@ export class CoreLoginSitePage { | |||||||
|      * Show an error that aims people to solve the issue. |      * Show an error that aims people to solve the issue. | ||||||
|      * |      * | ||||||
|      * @param {string} url The URL the user was trying to connect to. |      * @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 { |     protected showLoginIssue(url: string, error: any): void { | ||||||
|         const modal = this.modalCtrl.create('CoreLoginSiteErrorPage', { siteUrl: url, issue: error }); |         const modal = this.modalCtrl.create('CoreLoginSiteErrorPage', { | ||||||
|  |             siteUrl: url, | ||||||
|  |             issue: this.domUtils.getErrorMessage(error) | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|         modal.present(); |         modal.present(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -363,7 +363,7 @@ export class CoreSitesProvider { | |||||||
|             return this.checkSiteWithProtocol(siteUrl, protocol).catch((error) => { |             return this.checkSiteWithProtocol(siteUrl, protocol).catch((error) => { | ||||||
|                 // Do not continue checking if a critical error happened.
 |                 // Do not continue checking if a critical error happened.
 | ||||||
|                 if (error.critical) { |                 if (error.critical) { | ||||||
|                     return Promise.reject(error.error); |                     return Promise.reject(error); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 // Retry with the other protocol.
 |                 // Retry with the other protocol.
 | ||||||
| @ -371,13 +371,17 @@ export class CoreSitesProvider { | |||||||
| 
 | 
 | ||||||
|                 return this.checkSiteWithProtocol(siteUrl, protocol).catch((secondError) => { |                 return this.checkSiteWithProtocol(siteUrl, protocol).catch((secondError) => { | ||||||
|                     if (secondError.critical) { |                     if (secondError.critical) { | ||||||
|                         return Promise.reject(secondError.error); |                         return Promise.reject(secondError); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     // Site doesn't exist. Return the error message.
 |                     // Site doesn't exist. Return the error message.
 | ||||||
|                     return Promise.reject(this.textUtils.getErrorMessageFromError(error) || |                     if (this.textUtils.getErrorMessageFromError(error)) { | ||||||
|                             this.textUtils.getErrorMessageFromError(secondError) || |                         return Promise.reject(error); | ||||||
|                             this.translate.instant('core.cannotconnect')); |                     } 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 the error message.
 | ||||||
|                 return Promise.reject(this.textUtils.getErrorMessageFromError(error) || |                 if (this.textUtils.getErrorMessageFromError(error)) { | ||||||
|                         this.textUtils.getErrorMessageFromError(secondError)); |                     return Promise.reject(error); | ||||||
|  |                 } else { | ||||||
|  |                     return Promise.reject(secondError); | ||||||
|  |                 } | ||||||
|             }); |             }); | ||||||
|         }).then(() => { |         }).then(() => { | ||||||
|             // Create a temporary site to check if local_mobile is installed.
 |             // Create a temporary site to check if local_mobile is installed.
 | ||||||
| @ -456,7 +463,9 @@ export class CoreSitesProvider { | |||||||
|                         // Error, check if not supported.
 |                         // Error, check if not supported.
 | ||||||
|                         if (error.available === 1) { |                         if (error.available === 1) { | ||||||
|                             // Service supported but an error happened. Return error.
 |                             // Service supported but an error happened. Return error.
 | ||||||
|                             return Promise.reject({ error: error.error }); |                             error.critical = true; | ||||||
|  | 
 | ||||||
|  |                             return Promise.reject(error); | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|                         return data; |                         return data; | ||||||
|  | |||||||
| @ -598,6 +598,64 @@ export class CoreDomUtilsProvider { | |||||||
|         return this.textUtils.decodeHTML(this.translate.instant('core.error')); |         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. |      * Retrieve component/directive instance. | ||||||
|      * Please use this function only if you cannot retrieve the instance using parent/child methods: ViewChild (or similar) |      * 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. |      * @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 = ''; |         const message = this.getErrorMessage(error, needsTranslate); | ||||||
| 
 | 
 | ||||||
|         if (typeof error == 'object') { |         if (message === null) { | ||||||
|             if (this.debugDisplay) { |             // Message doesn't need to be displayed, stop.
 | ||||||
|                 // Get the debug info. Escape the HTML so it is displayed as it is in the view.
 |             return Promise.resolve(null); | ||||||
|                 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; |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime); |         return this.showAlert(this.getErrorTitle(message), message, undefined, autocloseTime); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user