How to conditionally execute the then(Mono<T>) operator?
I have a method that returns Mono<Void>. It can also return an error signal. I want to use the then operator (or any other operator), only when the previous operation completes without an error signal.
Can someone help me to find the right supplier operator?
public static void main(String[] args) {
Mono.just("GOOD_SIGNAL")//It can also be a BAD_SIGNAL
.flatMap(s -> firstMethod(s))
.then(secondMethod())
.subscribe()
;
}
private static Mono<String> secondMethod() {
//This method call is only valid when the firstMethod is success
return Mono.just("SOME_SIGNAL");
}
private static Mono<Void> firstMethod(String s) {
if ("BAD_SIGNAL".equals(s)) {
Mono.error(new Exception("Some Error occurred"));
}
return Mono
.empty()//Just to illustrate that this function return Mono<Void>
.then();
}
-Thanks