javascriptangularangular11

Don't cancel the first observable if the second fails, how to keep it (forkJoin, zip). Angular 11


I have parallel API calls. How to continue getting data from one of them if second one failed?

forkJoin([a,b])
      .subscribe({
        next: ((data) => {
          const [first, second] = data;
        })


Solution

  • It seems to me that combineLatest is what you are looking for, with a catchError to each of your observables to manage errors. Something like:

    combineLatest([
      obs1$.pipe(catchError(() => of(null)),
      obs2$.pipe(catchError(() => of(null)),
    ]).subscribe(([first, second]) => { console.log(first,second); });