|
| 1 | +import { ErrorHandler } from '@angular/core'; |
| 2 | + |
1 | 3 | /**
|
2 |
| - * This class is an internal error handler for Ionic. We can often add |
3 |
| - * some nice goodies to the dev/debugging process by reporting to our |
4 |
| - * dev server. To use this class, call `IonicErrorHandler.handleError(err)` from |
5 |
| - * inside a custom `ErrorHandler` as described here: https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html |
| 4 | + * The `IonicErrorHandler` intercepts the default `Console` error handling |
| 5 | + * and displays runtime errors as an overlay when using Ionic's Dev Build Server. |
| 6 | + * We can often add some nice goodies to the dev/debugging process by reporting |
| 7 | + * to our dev server and improving the error's readability. |
| 8 | + * |
| 9 | + * |
| 10 | + * ### IonicErrorHandler Example |
| 11 | + * |
| 12 | + * ```typescript |
| 13 | + * import { NgModule, ErrorHandler } from '@angular/core'; |
| 14 | + * import { IonicErrorHandler } from 'ionic-angular'; |
| 15 | + * |
| 16 | + * @NgModule({ |
| 17 | + * providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }] |
| 18 | + * }) |
| 19 | + * class AppModule {} |
| 20 | + * ``` |
| 21 | + * |
| 22 | + * |
| 23 | + * ### Custom Error Handlers |
| 24 | + * |
| 25 | + * Custom error handlers can be built to replace the default, or extend Ionic's |
| 26 | + * error handler. |
| 27 | + * |
| 28 | + * ```typescript |
| 29 | + * class MyErrorHandler implements ErrorHandler { |
| 30 | + * handleError(err: any): void { |
| 31 | + * // do something with the error |
| 32 | + * } |
| 33 | + * } |
| 34 | + * |
| 35 | + * @NgModule({ |
| 36 | + * providers: [{ provide: ErrorHandler, useClass: MyErrorHandler }] |
| 37 | + * }) |
| 38 | + * class AppModule {} |
| 39 | + * ``` |
| 40 | + * |
| 41 | + * More information about Angular's [`ErrorHandler`](https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html). |
6 | 42 | */
|
7 |
| -export class IonicErrorHandler { |
8 |
| - static handleError(err: any): void { |
9 |
| - let server = window['IonicDevServer']; |
10 |
| - if (server) { |
11 |
| - server.handleError(err); |
12 |
| - } |
| 43 | +export class IonicErrorHandler extends ErrorHandler { |
| 44 | + constructor() { |
| 45 | + super(false); |
| 46 | + } |
| 47 | + handleError(err: any): void { |
| 48 | + super.handleError(err); |
| 49 | + try { |
| 50 | + const devServer = window['IonicDevServer']; |
| 51 | + if (devServer) { |
| 52 | + devServer.handleError(err); |
| 53 | + } |
| 54 | + } catch (e) {} |
13 | 55 | }
|
14 | 56 | }
|
0 commit comments