Javascript 角度全局异常处理程序不工作(Typescript)

Javascript 角度全局异常处理程序不工作(Typescript),javascript,angular,typescript,observable,Javascript,Angular,Typescript,Observable,我已经在Angular 4(Typescript)中设置了一个全局事件处理程序,但无法捕获onerror处理程序的RX subscribe方法中出现的错误。signin方法基于对http.post的调用返回一个可观察对象,http.post反过来调用Identity Server 4(connect/token) 全局事件处理程序不起作用。我已经测试了抛出异常,处理程序捕捉到订阅方法之外的错误 您知道如何让全局事件处理程序捕获onerror处理程序的subscribe方法中引发的错误吗?我尝试过

我已经在Angular 4(Typescript)中设置了一个全局事件处理程序,但无法捕获onerror处理程序的RX subscribe方法中出现的错误。signin方法基于对http.post的调用返回一个可观察对象,http.post反过来调用Identity Server 4(connect/token)

全局事件处理程序不起作用。我已经测试了抛出异常,处理程序捕捉到订阅方法之外的错误

您知道如何让全局事件处理程序捕获onerror处理程序的subscribe方法中引发的错误吗?我尝试过“抛出错误”和“Observable.throw…”语句,但都不起作用。我认为问题在于,这些异常不会传播或被吞没。我不想为了处理错误而必须手动调用全局事件处理程序方法

签名

this.authentication.signin(this.model.userName, this.model.password)
        .subscribe(
       () => {
           // Optional strategy for refresh token through a scheduler.
           this.authentication.scheduleRefresh();

           // Gets the redirect URL from authentication service.
           // If no redirect has been set, uses the default.
           const redirect: string = this.authentication.redirectUrl
               ? this.authentication.redirectUrl
               : '/home';

           // Redirects the user.
           this.router.navigate([redirect]);
       },
       (error: any) => {

           const result: any = error.json();

           if (result == null) {
               throw error;
           }
           if (result.error !== "invalid_grant") {
               throw error;
           }

           this.error.error("Invalid user name or password");

       });
global.error.ts

export class GlobalErrorHandler implements ErrorHandler {
constructor(private injector: Injector) {
}

handleError(error: any) {
    //const loggingService = this.injector.get(LoggingService);
    const location = this.injector.get(LocationStrategy);
    const message = error.message ? error.message : error.toString();
    const url = location instanceof PathLocationStrategy
        ? location.path() : '';
    // get the stack trace, lets grab the last 10 stacks only
    StackTrace.fromError(error).then((stackframes: any) => {
        const stackString = stackframes
            .splice(0, 20)
            .map(function (sf: any) {
                return sf.toString();
            }).join('\n');
        console.log({ message, url, stack: stackString });
        // log on the server
        //loggingService.log({ message, url, stack: stackString });
    });
    throw error;
}
}
也许这可以指导你-