RxJS + Angular 4 throw error in subscribe onError not bubbling out to custom global error handler

Viewed 2071

I have an API call that throws an exception. In my component I have a subscription on the api observable, and I want to throw an error received on the subscription out to be handled by my custom angular error handler.

However, in my code I throw the error in the onError handler, but it is not bubbling out to the global error handler.

Component call:

this.searchService.search(this.searchField.value)
          .subscribe(
            result => { this.result = result.artists.items; },
            err => { 
              console.log('subscribe on error');
              this.errorMessage = 'Error Occurred';
              //This error does not bubble out to the global angular error handler.
              throw new Error('Error here'); 
            },
        () => { console.log('Completed'); }
          );

Service Call:

search(term: string) {
    return this.http.request(`https://api.spotify.com/v1/dsds?q=${term}&type=artist`)
      .map((response) => {
        return Observable.throw(result);
      }).catch((err: any)=>{
        console.log('in catch in service');
         return Observable.throw(err);

      })
      ;
  }

Here is a link to a plnkr to demonstrate the problem. using the latest version of rxjs.

https://plnkr.co/edit/BI4njaMbtR7pfplQvgru?p=preview

I am using http.request in this case because in my actual app we are using NSwag studio to generate the typescript clients for calling the web apis.

** Update**

I created a new plunker and went to a previous version of rxjs, and in version 5.0.1 an exception throw in the catch, does bubble up to angular's global error handler.

see example here: https://plnkr.co/edit/ZMhTNbBfWaz4Y0TiI0jR?p=preview

The only difference is the version of rxjs in the config.js file.

   'rxjs': 'https://npmcdn.com/rxjs@5.0.1',
0 Answers
Related