mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 14:01:20 +08:00
feat(IonicErrorHandler): custom ionic error handler provider
This commit is contained in:
@ -1,14 +1,56 @@
|
|||||||
|
import { ErrorHandler } from '@angular/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is an internal error handler for Ionic. We can often add
|
* The `IonicErrorHandler` intercepts the default `Console` error handling
|
||||||
* some nice goodies to the dev/debugging process by reporting to our
|
* and displays runtime errors as an overlay when using Ionic's Dev Build Server.
|
||||||
* dev server. To use this class, call `IonicErrorHandler.handleError(err)` from
|
* We can often add some nice goodies to the dev/debugging process by reporting
|
||||||
* inside a custom `ErrorHandler` as described here: https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html
|
* 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 {
|
export class IonicErrorHandler extends ErrorHandler {
|
||||||
static handleError(err: any): void {
|
constructor() {
|
||||||
let server = window['IonicDevServer'];
|
super(false);
|
||||||
if (server) {
|
}
|
||||||
server.handleError(err);
|
handleError(err: any): void {
|
||||||
}
|
super.handleError(err);
|
||||||
|
try {
|
||||||
|
const devServer = window['IonicDevServer'];
|
||||||
|
if (devServer) {
|
||||||
|
devServer.handleError(err);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user