2016-06-02 4 views
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가 콘솔에 오류를 기록하도록 작동시키는 방법과 추가 오류 처리도 수행됩니까?

답변

0

동일한 문제점이 있지만 두 번째 매개 변수 (rethrowException)의 생성자에 false을 전달하여 작동시킬 수있었습니다.

constructor() { 
    super (new _ArrayLogger(), false); 
} 

매개 변수의 이름은 올바른 값이 실제로 true 것을 제안; 조금 뒤떨어져있는 것 같지만 작동합니다.