Skip to content

Commit

Permalink
feat(IonicErrorHandler): custom ionic error handler provider
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 10, 2016
1 parent ae1197a commit 6b77772
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 deletions src/util/ionic-error-handler.ts
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) {}
}
}

0 comments on commit 6b77772

Please sign in to comment.