Here is a scenario where a series of Observables are chained together. Is it possible to prevent the subsequent chain from executing if an error is thrown by 'parentObs1'?
import { throwError } from "rxjs";
import { mergeMap, catchError } from "rxjs/operators";
const parentObs1 = throwError("parentObs1");
const childObs2 = throwError("childObs2");
const grandChildObs3 = throwError("grandChildObs3");
parentObs1
.pipe(
mergeMap(() => childObs2),
catchError((error) => throwError("Error in Obs1 CatchError block"))
)
// How can we avoid running this pipe if the previous one throws an error?
.pipe(
mergeMap(() => grandChildObs3),
catchError((error) => throwError("Error in Obs2 CatchError block"))
)
.subscribe(
() => {},
(error: any) => {
console.log(error); // It is expected to print 'Error in Obs1 CatchError block' but currently displays 'Error in Obs2 CatchError block'
}
);