wondering how to bubble up errors from observable to subscriber’s err function without terminating the stream
for example, making http calls, when the result is a 404 or any other error i catch and throw error in stream. This causes stream to terminate and enter err function block in subscriber
However, is there a way to catch and keep stream open and pass on value to error block in the subscriber. This is to deal with the said 404 error in the subscribers and not in stream. For doing things like error handling and UI changes based on error.
UPDATE WITH CODE: I have a subscriber like so:
this.blahService.getSomething(id)
.subscribe((response: Response) =>{
this.cancelBtnText= 'Cancelled';
this.canCancel = false;
},
err =>{
console.log('ERRROR:::', err);
});
and Subject like so:
return this.http.get(this.config.apiEndpointUrl, this.options)
.map((r: Response) => <blah>r.json())
.catch((error: any) => {
console.error('A friendly error occurred', error);
return Observable.throw(error.message || error);
});
on http errors this will cause catch
function to be called. However, when i throw error this terminates stream and all its subscribers, so the next time the event comes around to call service my subscriber is no longer listening to it and is completely unsubscribed, and therefore, no information is ever sent back to subscribe.
This changes when i change the throw
to a .empty()
, in the service, since this does not terminate stream but now the error
function in subscriber is no longer called.