Код: Выделить всё
if (!request.isValid()) {
throw new ValidationException("Its not valid");
}
if (!request.isCorrect()) {
throw new IncorrectException();
}
return Mono.just(
someService.process(request)
);
Код: Выделить всё
return Mono.just(request)
.filter(req -> !req.isValid())
.switchIfEmpty(Mono.error(new ValidationException("Its not valid")))
.filter(req -> !req.isCorrect())
.switchIfEmpty(Mono.error(new IncorrectException()))
.flatMap(req -> Mono.just(someService.process(req)));
Подробнее здесь: https://stackoverflow.com/questions/634 ... tchifempty