-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(IonicErrorHandler): custom ionic error handler provider
- Loading branch information
1 parent
ae1197a
commit 6b77772
Showing
1 changed file
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) {} | ||
} | ||
} |