0
나는 ExceptionHandler 클래스를 확장 한 :두 번
import {Injectable, ExceptionHandler} from '@angular/core';
export class FirstError extends Error {
handle() {
console.log("This is firstError handler");
}
}
export class AnotherError extends Error {
handle() {
console.log("This is AnotherError handler");
}
}
export class _ArrayLogger {
res = [];
log(s: any): void { this.res.push(s); }
logError(s: any): void { this.res.push(s); }
logGroup(s: any): void { this.res.push(s); }
logGroupEnd() {};
}
@Injectable()
export class CustomExceptionHandler extends ExceptionHandler {
constructor() {
super (new _ArrayLogger(), true);
}
call(exception: any, stackTrace = null, reason = null) {
// I want to have original handler log exceptions to console
super.call(exception, stackTrace, reason);
// If exception is my type I want to do some additional actions
if (exception.originalException instanceof Error) {
exception.originalException.handle();
}
}
}
내 목표는 원래 Angular2 ExceptionHandler로 콘솔에 오류를 기록 super.call 있고, 또한 내 자신의 예외 핸들을하는 것입니다. 불행히도, 그런 시나리오에서 슈퍼는 에러가 발생했을 때만 호출됩니다. 두 번째, 세 번째가 발생하면 슈퍼가 호출되지 않습니다. 원본 console.log가 콘솔에 오류를 기록하도록 작동시키는 방법과 추가 오류 처리도 수행됩니까?