I am trying to perform a validation and if no exception is thrown, then perform an action. The problem is that the code is async, so the "CompletePlanConfirm()" method is always run, but must be skipped if exception occurs. FirstCheck and secondCheck return Observable. is there a way to accomplish this?
completePlan() {
try {
this.validatePlan();
this.completePlanConfirm();
} catch (error) {
throw error
}
}
validatePlan() {
this.planService.FirstCheck(this.plan.id).subscribe(
data => {
if (!data.result) {
throw Error('Error 1')
}
});
this.planService.SecondCheck(this.plan.id).subscribe(
data => {
if (!data.result) {
throw Error('Error 2')
}
});
}
completePlansupposed to treat errors fromvalidatePlan?catch(error) { throw error }doesn't make much sense.