forked from EVOgeek/Vmeda.Online
		
	MOBILE-4047 errors: Admit buttons when creating a CoreError
This commit is contained in:
		
							parent
							
								
									c1cae77bbc
								
							
						
					
					
						commit
						7dfcd8bfe3
					
				| @ -23,7 +23,7 @@ import { CoreAjaxWSError } from './ajaxwserror'; | |||||||
| import { CoreCaptureError } from './captureerror'; | import { CoreCaptureError } from './captureerror'; | ||||||
| import { CoreNetworkError } from './network-error'; | import { CoreNetworkError } from './network-error'; | ||||||
| import { CoreSiteError } from './siteerror'; | import { CoreSiteError } from './siteerror'; | ||||||
| import { CoreErrorWithTitle } from './errorwithtitle'; | import { CoreErrorWithOptions } from './errorwithtitle'; | ||||||
| import { CoreHttpError } from './httperror'; | import { CoreHttpError } from './httperror'; | ||||||
| 
 | 
 | ||||||
| export const CORE_ERRORS_CLASSES: Type<unknown>[] = [ | export const CORE_ERRORS_CLASSES: Type<unknown>[] = [ | ||||||
| @ -36,6 +36,6 @@ export const CORE_ERRORS_CLASSES: Type<unknown>[] = [ | |||||||
|     CoreSilentError, |     CoreSilentError, | ||||||
|     CoreSiteError, |     CoreSiteError, | ||||||
|     CoreWSError, |     CoreWSError, | ||||||
|     CoreErrorWithTitle, |     CoreErrorWithOptions, | ||||||
|     CoreHttpError, |     CoreHttpError, | ||||||
| ]; | ]; | ||||||
|  | |||||||
| @ -12,20 +12,24 @@ | |||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
|  | import { AlertButton } from '@ionic/angular'; | ||||||
| import { CoreError } from './error'; | import { CoreError } from './error'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Error with an explicit title describing the problem (instead of just "Error" or a generic message). |  * Error with an explicit title describing the problem (instead of just "Error" or a generic message). | ||||||
|  * This title should be used to communicate the problem with users, and if it's undefined it should be omitted. |  * This title should be used to communicate the problem with users, and if it's undefined it should be omitted. | ||||||
|  |  * The error also may contain customizable action buttons. | ||||||
|  */ |  */ | ||||||
| export class CoreErrorWithTitle extends CoreError { | export class CoreErrorWithOptions extends CoreError { | ||||||
| 
 | 
 | ||||||
|     title?: string; |     title?: string; | ||||||
|  |     buttons?: AlertButton[]; | ||||||
| 
 | 
 | ||||||
|     constructor(message?: string, title?: string) { |     constructor(message?: string, title?: string, buttons?: AlertButton[]) { | ||||||
|         super(message); |         super(message); | ||||||
| 
 | 
 | ||||||
|         this.title = title; |         this.title = title; | ||||||
|  |         this.buttons = buttons; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -51,7 +51,7 @@ import { CoreRedirectPayload } from './navigator'; | |||||||
| import { CoreSitesFactory } from './sites-factory'; | import { CoreSitesFactory } from './sites-factory'; | ||||||
| import { CoreText } from '@singletons/text'; | import { CoreText } from '@singletons/text'; | ||||||
| import { CoreLoginHelper } from '@features/login/services/login-helper'; | import { CoreLoginHelper } from '@features/login/services/login-helper'; | ||||||
| import { CoreErrorWithTitle } from '@classes/errors/errorwithtitle'; | import { CoreErrorWithOptions } from '@classes/errors/errorwithtitle'; | ||||||
| import { CoreAjaxError } from '@classes/errors/ajaxerror'; | import { CoreAjaxError } from '@classes/errors/ajaxerror'; | ||||||
| import { CoreAjaxWSError } from '@classes/errors/ajaxwserror'; | import { CoreAjaxWSError } from '@classes/errors/ajaxwserror'; | ||||||
| import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; | import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; | ||||||
| @ -870,7 +870,7 @@ export class CoreSitesProvider { | |||||||
| 
 | 
 | ||||||
|         const siteUrlAllowed = await CoreLoginHelper.isSiteUrlAllowed(site.getURL(), false); |         const siteUrlAllowed = await CoreLoginHelper.isSiteUrlAllowed(site.getURL(), false); | ||||||
|         if (!siteUrlAllowed) { |         if (!siteUrlAllowed) { | ||||||
|             throw new CoreErrorWithTitle(Translate.instant('core.login.sitenotallowed')); |             throw new CoreErrorWithOptions(Translate.instant('core.login.sitenotallowed')); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.currentSite = site; |         this.currentSite = site; | ||||||
|  | |||||||
| @ -1344,7 +1344,6 @@ export class CoreDomUtilsProvider { | |||||||
| 
 | 
 | ||||||
|         const alertOptions: AlertOptions = { |         const alertOptions: AlertOptions = { | ||||||
|             message: message, |             message: message, | ||||||
|             buttons: [Translate.instant('core.ok')], |  | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         if (this.isNetworkError(message, error)) { |         if (this.isNetworkError(message, error)) { | ||||||
| @ -1355,6 +1354,12 @@ export class CoreDomUtilsProvider { | |||||||
|             alertOptions.header = Translate.instant('core.error'); |             alertOptions.header = Translate.instant('core.error'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         if (typeof error !== 'string' && 'buttons' in error && typeof error.buttons !== 'undefined') { | ||||||
|  |             alertOptions.buttons = error.buttons; | ||||||
|  |         } else { | ||||||
|  |             alertOptions.buttons = [Translate.instant('core.ok')]; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         return this.showAlertWithOptions(alertOptions, autocloseTime); |         return this.showAlertWithOptions(alertOptions, autocloseTime); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -26,6 +26,7 @@ import { CoreFileHelper } from '@services/file-helper'; | |||||||
| import { CoreDomUtils } from './dom'; | import { CoreDomUtils } from './dom'; | ||||||
| import { CoreText } from '@singletons/text'; | import { CoreText } from '@singletons/text'; | ||||||
| import { CoreUrl } from '@singletons/url'; | import { CoreUrl } from '@singletons/url'; | ||||||
|  | import { AlertButton } from '@ionic/angular'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Different type of errors the app can treat. |  * Different type of errors the app can treat. | ||||||
| @ -38,6 +39,7 @@ export type CoreTextErrorObject = { | |||||||
|     debuginfo?: string; |     debuginfo?: string; | ||||||
|     backtrace?: string; |     backtrace?: string; | ||||||
|     title?: string; |     title?: string; | ||||||
|  |     buttons?: AlertButton[]; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
| @ -166,7 +168,7 @@ export class CoreTextUtilsProvider { | |||||||
|             improvedError = error; |             improvedError = error; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         improvedError.title = title; |         improvedError.title = improvedError.title || title; | ||||||
| 
 | 
 | ||||||
|         return improvedError; |         return improvedError; | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user