user776686
user776686

Reputation: 8665

Handling errors when using combineLatest on several service calls

With the following piece of code (taken from an @Effect() in ngrx/store)

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

What would be the most succinct yet correct pattern to catch the errors? Should the .catch follow every getData* call? We don't want .catch() at the end of the main @Effect() chain, do we?

The question is similar to this one, yet a bit different in that I don't a .subscribe() call here.

Upvotes: 2

Views: 3456

Answers (1)

Robin Dijkhof
Robin Dijkhof

Reputation: 19288

This totally depends on the desired behaviour. Lets asume you are fetching 3 animals which you will display. What do you want to happen when one fail?

  • Do not display any animal. -> add a catch to the end
  • Display the other animals. -> add catch to each data call.

Upvotes: 4

Related Questions