The methods you might want to check out are: onErrorResume(Throwable, Mapper) or onErrorResume(Predicate)
For example your code could look something like this:
public Mono<B> someMethod( Object arg ) {
Mono monoA = Mono.just( arg ).flatMap( adapter1::doSomething );
return monoA.onErrorResume({ Throwable e ->
return B::buildSuccessResponse
});
}
In this case the onErrorResume would handle any error emitted from adapter1::doSomething. Keep in mind that when an error is emitted - no further 'map', 'flatMap' or any other method is invoked on subsequent Monos since an error will be passed down instead of the expected object.
You could then simply chain it all to look like:
public Mono<B> someMethod( Object arg ) {
return Mono.just( arg ).flatMap( adapter1::doSomething ).onErrorResume({ Throwable e ->
return B::buildSuccessResponse
});
}
Keep in mind that all method that start with 'do' like 'doOnError' will execute the closure provided without modifying the 'emitted' object.