Angular2的ErrorHandler,错误破坏了代码
问题描述:
import { Injectable, ErrorHandler, Inject, Injector } from '@angular/core';
import { MessengerService } from '../services';
import { MessageTypeEnum } from '../../shared';
@Injectable()
export class AppErrorHandler extends ErrorHandler {
constructor(private messengerService: MessengerService) {
super(true);
}
handleError(error) {
console.log('ERROR!');
console.log(error);
this.messengerService.showMessage('Nastala chyba', 'Předem se omlouváme za vzniklé potíže', MessageTypeEnum.Error);
}
}
测井工程,但应用程序仍然崩溃+日志跟踪HTTP错误一样好,但我想实现一个目标,即每个错误都会被记录,但其余的角度应用程序将正常工作。错误的Angular2的ErrorHandler,错误破坏了代码
例子: value.getMonth不在ViewWrappedError.ZoneAwareError OR 404,功能500 HTTP错误
答
只要不重新抛出错误。
constructor(private messengerService: MessengerService) {
super(true);
}
你需要把假这里
super(false);
文档: https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html
来源:https://github.com/angular/angular/blob/master/modules/%40angular/core/src/error_handler.ts
+0
我试过...例如api返回500,并且应用程序崩溃 – user3599497
请告诉我的错误? – Smit