RxJS 中有什么方法可以在其中一个失败时独立地从多个不同的 http 调用中收集结果?

What is the way in RxJS to keep collecting results from multiple and different http calls independently on when one of those fails?

我用过 zip 和 forkJoin

return forkJoin({
  a: this.getA(),
  b: this.getB(),
  c: this.getC()
})

问题是,如果其中一个调用失败,所有调用都会被取消,而我仍想从未失败的调用中收集数据 将它们分开制作是唯一的方法吗?

要解决您的问题,您必须捕获错误并在内部 observable

中正确处理它
return forkJoin({
  a: this.getA(),
  b: this.getB(),
  c: this.getC().pipe(catchError(error => of(error)))
})

// If getC fails, you would get A and B

我的问题是,您是否必须仅将此处理添加到最后一个元素或所有元素。您将不得不自己尝试,请在评论中告诉我。

请参阅HERE 示例 5:当出现一个内部可观察错误时获得成功的结果