From 5821f95095dcecc64ef3ac0c206781c5308de287 Mon Sep 17 00:00:00 2001 From: Moreno Bruschi Date: Wed, 13 Nov 2019 09:07:37 +0100 Subject: [PATCH] feat(errors): added global error handler class Add global error handler and set it as provider in main module Could be a starting point for issue #4 --- src/app/app.module.ts | 11 +++++++++-- src/app/shared/handlers/global-error-handler.ts | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/app/shared/handlers/global-error-handler.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 91094c6..d4030f1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core'; +import { NgModule, ErrorHandler } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { CoreModule } from './core/core.module'; @@ -7,6 +7,7 @@ import { CommandModule } from './features/command/command.module'; import { PatternModule } from './features/pattern/pattern.module'; import { AppComponent } from '@app/app.component'; +import { GlobalErrorHandler } from './shared/handlers/global-error-handler'; @NgModule({ declarations: [ @@ -19,6 +20,12 @@ import { AppComponent } from '@app/app.component'; CommandModule, PatternModule ], - bootstrap: [AppComponent] + bootstrap: [AppComponent], + providers: [ + { + provide: ErrorHandler, + useClass: GlobalErrorHandler + } + ] }) export class AppModule { } diff --git a/src/app/shared/handlers/global-error-handler.ts b/src/app/shared/handlers/global-error-handler.ts new file mode 100644 index 0000000..9eb572b --- /dev/null +++ b/src/app/shared/handlers/global-error-handler.ts @@ -0,0 +1,10 @@ +import { ErrorHandler, Injectable} from '@angular/core'; + +@Injectable() +export class GlobalErrorHandler implements ErrorHandler { + constructor() { } + + handleError(error: any): void { + console.log(error); + } +}