I'm zipping a three observables, each of the three observables has it's own "success" callback using .pipe(tap() => {...});. This works fine when all three observables execute without error, but if one of the observables errors out, then none of the tap methods execute. How can I have the tap methods always execute if that observable runs successfully?
var request1 = Observable.create(...); //Pretend this one will fail (though request2 or request3 could also fail)
var request2 = Observable.create(...);
var request3 = Observable.create(...);
request1.pipe(tap(() => {
//Unique success callback should always run if request1 succeeds, even if request2 or request 3 fails.
}));
request2.pipe(tap(() => {
//Unique success callback should always run if request2 succeeds, even if request1 or request 3 fails.
}));
request3.pipe(tap(() => {
//Unique success callback should always run if request3 succeeds, even if request1 or request 2 fails.
}));
var observable = zip(request1, request2, request3);
observable.subscribe(() => {
//Do something when all three execute successfully
});
I believe this is expected and the appropriate behavior for what you're dealing with. You probably want to look at using piping the catchError lettable into each of your requests and returning an empty observable.
request1.pipe(tap(() => {
//Unique success callback
}), catchError((err) => {
return empty();
}));
That way you handle the error of that observable without breaking the new zip.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With