Is there a way to handle async code in a validation process where an action should only be performed if no exception is thrown? For example, the "CompletePlanConfirm()" method should only run if no exception occurs. The functions FirstCheck and SecondCheck return Observables. How can this be achieved?
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')
}
});
}