Skip to content

Commit

Permalink
feat(errors): added global error handler class
Browse files Browse the repository at this point in the history
Add global error handler and set it as provider in main module

Could be a starting point for issue acadevmy#4
  • Loading branch information
Moreno Bruschi committed Nov 13, 2019
1 parent 9b5fd7b commit 5821f95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: [
Expand All @@ -19,6 +20,12 @@ import { AppComponent } from '@app/app.component';
CommandModule,
PatternModule
],
bootstrap: [AppComponent]
bootstrap: [AppComponent],
providers: [
{
provide: ErrorHandler,
useClass: GlobalErrorHandler
}
]
})
export class AppModule { }
10 changes: 10 additions & 0 deletions src/app/shared/handlers/global-error-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ErrorHandler, Injectable} from '@angular/core';

@Injectable()
export class GlobalErrorHandler implements ErrorHandler {
constructor() { }

handleError(error: any): void {
console.log(error);
}
}

0 comments on commit 5821f95

Please sign in to comment.