显示错误并恢复流

show the error and resume the stream

我有一个实时搜索,但如果由于某种原因 forkJoin 失败,一切都会停止。错误后我尝试寻找的任何新词都不起作用。如何显示错误并正常恢复流以便我可以搜索其他词?

this.search$
  .distinctUntilChanged()
  .switchMap((query) => Rx.Observable.forkJoin(sources)) // If this fails the search stops working
  .subscribe((results) => console.log(results));

试试这个:

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));

请注意 catch()forkJoin() 上,而不是 switchMap()...