gpt4 book ai didi

angular - Angular2 ErrorHandler,错误导致代码中断

转载 作者:行者123 更新时间:2023-12-03 08:50:24 25 4
gpt4 key购买 nike

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错误,但是我想实现一个目标,即将记录每个错误,但其他 Angular 应用程序将正常运行。

错误示例:
value.getMonth不是ViewWrappedError.ZoneAwareError的函数
要么
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

关于angular - Angular2 ErrorHandler,错误导致代码中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42555149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com