While the question may seem simple, finding reliable resources on error handling for Observables can be a challenge. I've been struggling to locate clear information online (or perhaps my search skills need improvement).
In my scenario, I have an http request that returns an Observable of type Response. These Responses may contain either data or an error message. When there is data, I want to extract and parse it. But if the Response contains an error message, I want to skip all subsequent operators related to parsing and immediately execute the error function within the subscriber.
I currently achieve this by throwing an Error:
http.get(...).
...
.do(res=>{
if(res.error) throw new Error(res.error.message);
return res;
})
This approach successfully skips the parsing operators and triggers the error function. However, the issue arises after encountering an error—the Subscriber stops accepting data at that point.
Upon examining the Subscriber post-error, I observed that both the properties closed and isStopped are set to true. My goal is to prevent this premature closure and maintain the Observable active even after errors occur. How can I accomplish this?
Thank you