angular2 rxjs observable forkjoin

前端 未结 2 883
遥遥无期
遥遥无期 2020-12-03 05:23

Is it possible to continue forkjoin http.get requests even if one of the requests fails.

I\'m looking to a similar function of $q.allSettled in angular2.

Se

2条回答
  •  爱一瞬间的悲伤
    2020-12-03 05:43

    You could leverage the catch operator for each observable to intercept the error and return another observable in such cases.

    Here is a sample:

    return Observable.forkJoin(
      this.http.get('/some-url')
             .map((res:Response) => res.json())
             .catch(res:Response => Observable.of({}),
      this.http.get('/some-other-url')
             .map((res:Response) => res.json())
             .catch(res:Response => Observable.of({}),
    );
    

提交回复
热议问题