I have a scenario where two observable calls are dependent on each other. Everything works fine, but when an error occurs in the response, I need to trigger another observable to rollback the transaction.
Below is my code:
return this.myService.createOrder()
.pipe(
concatMap((res: MyResponse) => this.addProduct(res.orderId, PRODUCT_ID))
).subscribe({
error: (error: any): void => // TODO: Call another observable here passing res.orderId to rollback transaction
});
In the TODO section, I intend to call another service if there's an error with the res.orderId
, but I want to avoid nested subscriptions.
Is there a way to achieve this without creating nested subscriptions?