I am using RxJs in an Angular 2 application to fetch data from an API for multiple pages in parallel and save any failed requests for future re-try.
To do so, I want to catch errors generated by flatMap-ing http get requests (code below) and continue with further stream processing. In case of error, my current solution causes stream to discontinue.
Rx.Observable.range(1, 5)
.flatMap(pageNo => {
params.set('page', ''+pageNo);
return this.http.get(this.API_GET, params)
.catch( (err) => {
//save request
return Rx.Observable.throw(new Error('http failed'));
});
})
.map((res) => res.json());
Let's say in above example, HTTP request for page 2 and 3 fails. I want to handle error (save failed request later retry) for both these request and let other requests continue and get mapped to json().
I tried using .onErrorResumeNext
instead of catch, but I am unable to make this work.