-
-
Save pvamshi/e4b6bbb3a9494c981ff06ff9c4b07883 to your computer and use it in GitHub Desktop.
Global UI error handler
This file contains hidden or 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
import {BrowserModule} from '@angular/platform-browser'; | |
import {ErrorHandler, NgModule, Injectable} from '@angular/core'; | |
import {AppComponent} from './app.component'; | |
@Injectable() | |
class UIErrorHandler extends ErrorHandler { | |
constructor() { | |
super(); | |
} | |
handleError(error) { | |
super.handleError(error); | |
alert(`Error occurred:${error.message}`); | |
} | |
} | |
@NgModule({ | |
declarations: [AppComponent], | |
imports: [BrowserModule], | |
// add the UI error handler | |
providers: [ | |
provide: ErrorHandler, | |
useClass: UIErrorHandler | |
}], | |
bootstrap: [AppComponent] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment