I have a real-time search, but if for some reason the forkJoin fails, everything stops working. Any new words I try to look for after the error do not work. How can I show the error and resume the stream normally so that I can search for other words?
this.search$
.distinctUntilChanged()
.switchMap((query) => Rx.Observable.forkJoin(sources)) // If this fails the search stops working
.subscribe((results) => console.log(results));
Try this:
this.search$
.distinctUntilChanged()
.switchMap((query) => Rx.Observable.forkJoin(sources)
// return empty results object, I used an empty array...
.catch(error => Observable.of([])))
.subscribe((results) => console.log(results));
Notice that catch()
is on forkJoin()
, not on switchMap()
...