【问题标题】:Handling errors when using combineLatest on several service calls在多个服务调用上使用 combineLatest 时处理错误
【发布时间】:2017-09-25 09:49:03
【问题描述】:

使用以下代码(取自ngrx/store 中的@Effect())

.switchMap(({token, param1, param2}) => {
  return Observable.combineLatest(
    this.service.getData2(token, param1),
    this.service.getData2(token, param2),
    this.service.getData3(token),
  );
})

捕捉错误的最简洁但正确的模式是什么? .catch 是否应该跟随每个getData* 电话?我们不希望 .catch() 位于主 @Effect() 链的末尾,对吗?

这个问题类似于this one,但有点不同,因为我在这里没有.subscribe() 电话。

【问题讨论】:

    标签: rxjs rxjs5 ngrx-effects


    【解决方案1】:

    这完全取决于所需的行为。假设您正在获取 3 只动物,您将展示它们。当一个人失败时你想发生什么?

    • 请勿展示任何动物。 -> 在末尾添加catch
    • 展示其他动物。 -> 在每个数据调用中添加catch

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 1970-01-01
      相关资源
      最近更新 更多