如何对 combineLatest 中的每个函数进行单独的错误处理?

How to have a separate error handling for each function in combineLatest?

我需要处理这个 combineLatest 中每个函数的错误场景。我将在下面添加代码

const combined = combineLatest(
  this.myservice1.fn1(param),
  this.myservice2.fn2(), 
  this.myservice3.fn3());

const subscribe = combined.subscribe(
  ([fn1,fn2, fn3]) => {
    // operations i need to do
  },
  // how to handle error for fn1, fn2, fn3 separately
  (error) => {
  }
);

如有任何帮助,我们将不胜感激!

你可以在使用 combineLatest latest 之前捕获每个源 Observable 的错误,如果你想稍后处理它们或将它们转换为不同的错误,最终重新抛出它:

combineLatest(
  this.myservice1.fn1(param)
    .pipe(
      catchError(err => {
        if (err.whatever === 42) {
          // ... whatever
        }
        throw err;
      }),
    ),
  this.myservice2.fn2()
    .pipe(
      catchError(err => /* ... */),
    ),
  ...
)