我有一个关于新类ErrorHandler的问题(包含在RC.6中).
原文链接:https://www.f2er.com/angularjs/141645.html我从官方文档中做了一些例子:
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 {}
我编辑app.module文件后
import {MyErrorHandler} from "./error.module"; import {MyErrorModule } from "./error.module"; .. @NgModule({ imports: [ MyErrorModule .... ],... providers: [MyErrorHandler] ....
现在MyErrorHandler捕获错误:
throw new Error("my test error");
但它没有捕获http错误,如:“GET http://example.com/rest/user 401(未经授权)”.
任何人都可以解释一下吗?
提前致谢!