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