ErrorHandler en Angular2
Tengo una pregunta sobre la nueva clase ErrorHandler (se incluyó en RC.6).
Hice un ejemplo de documentos oficiales:https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html
import{ErrorHandler} from "@angular/core";
import{NgModule} from "@angular/core";
export class MyErrorHandler implements ErrorHandler {
call(error: any, stackTrace: any = null, reason: any = null) {
// do something with the exception
console.log("do something with the exception");
}
// I handle the given error.
public handleError( error: any ): void {
console.log("I handle the given error");
}
}
@NgModule({
providers: [
{
provide: ErrorHandler,
useClass: MyErrorHandler
}
]
})
export class MyErrorModule {}
Después de editar mi archivo app.module
import {MyErrorHandler} from "./error.module";
import {MyErrorModule } from "./error.module";
..
@NgModule({
imports: [
MyErrorModule
....
],
...
providers: [MyErrorHandler]
....
Ahora MyErrorHandler detecta errores:
throw new Error("my test error");
Pero no detecta errores http como: "OBTENERhttp://example.com/rest/user 401 (No autorizado) ". ¿Alguien me lo puede explicar?
¡Gracias por adelantado!