I've searched around quite a bit and haven't found anything that is helping me get over the hump. I think that I have implemented the Angular2 ExceptionHandler as required, but it is never getting called.
Main.ts:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import { AppComponent } from './app.component';
import { ExceptionHandler, Injector , provide, Provider} from '@angular/core';
import { APP_ROUTER_PROVIDERS } from './app.routes'; // <-- load in global routes and bootstrap them
import { ErrorHandler } from './errorhandler/error-handler.component';
bootstrap(AppComponent,[
APP_ROUTER_PROVIDERS,
disableDeprecatedForms(),
provideForms(),
provide(ExceptionHandler, {useClass: ErrorHandler})
])
error-handler.component.ts:
import { Component, Injectable, ExceptionHandler } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
import { APP_PROVIDERS } from '../app.providers';
@Component({
moduleId: module.id,
template: `Error happened here!!!!`,
directives: [ ROUTER_DIRECTIVES ],
providers: [ APP_PROVIDERS ]
})
@Injectable()
export class ErrorHandler extends ExceptionHandler {
call (exception: any, stackTrace?: any, reason?: string): void {
}
}
I have an HTTP error that I'm forcing to occur in one of my services (to test the exception handling) and would expect my "global" handler to get called. Am I missing something? Unfortunately, not a whole lot of documentation out there right now...
TIA.
James