Given the following reactive code:
operation1()
.then(operation2())
.onErrorMap(e -> revertOperation1().thenReturn(e).block())
.then(operation3())
.onErrorResume(e -> Mono.empty());
where each operation returns Mono<Void>.
Errors are propagated downstream, meaning that if either operation1() or operation2() fail then both onErrorMap(...) and onErrorResume(...) are executed.
How can I make it so that when an error occurs that is not propagated downstream?
More precisely:
- if operation1() fails, neither
onErrorMap(...)noronErrorResume(...)should be executed; - if operation2() fails, only
onErrorMap(...)should be executed but notonErrorResume(...).
onErrorStop exists, but that seems to work only in combination with onErrorContinue.
I could use only one onError at the end of the chain, but I don't know how to identify which operation returned the error.
Using spring-boot-starter-webflux.