diff --git a/src/util/ionic-error-handler.ts b/src/util/ionic-error-handler.ts index c564743c0e..fb67f12b2c 100644 --- a/src/util/ionic-error-handler.ts +++ b/src/util/ionic-error-handler.ts @@ -1,14 +1,56 @@ +import { ErrorHandler } from '@angular/core'; + /** - * This class is an internal error handler for Ionic. We can often add - * some nice goodies to the dev/debugging process by reporting to our - * dev server. To use this class, call `IonicErrorHandler.handleError(err)` from - * inside a custom `ErrorHandler` as described here: https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html + * The `IonicErrorHandler` intercepts the default `Console` error handling + * and displays runtime errors as an overlay when using Ionic's Dev Build Server. + * We can often add some nice goodies to the dev/debugging process by reporting + * to our dev server and improving the error's readability. + * + * + * ### IonicErrorHandler Example + * + * ```typescript + * import { NgModule, ErrorHandler } from '@angular/core'; + * import { IonicErrorHandler } from 'ionic-angular'; + * + * @NgModule({ + * providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }] + * }) + * class AppModule {} + * ``` + * + * + * ### Custom Error Handlers + * + * Custom error handlers can be built to replace the default, or extend Ionic's + * error handler. + * + * ```typescript + * class MyErrorHandler implements ErrorHandler { + * handleError(err: any): void { + * // do something with the error + * } + * } + * + * @NgModule({ + * providers: [{ provide: ErrorHandler, useClass: MyErrorHandler }] + * }) + * class AppModule {} + * ``` + * + * More information about Angular's [`ErrorHandler`](https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html). */ -export class IonicErrorHandler { - static handleError(err: any): void { - let server = window['IonicDevServer']; - if (server) { - server.handleError(err); - } +export class IonicErrorHandler extends ErrorHandler { + constructor() { + super(false); + } + handleError(err: any): void { + super.handleError(err); + try { + const devServer = window['IonicDevServer']; + if (devServer) { + devServer.handleError(err); + } + } catch (e) {} } }