我尝试使用 webclient 非阻塞方法验证验证码响应。所以它可以工作,但我需要我的方法返回布尔值而不是异常。我如何从订阅中返回值?
webClient
.post()
.uri(verifyUri)
.exchange()
.flatMap(res -> res.bodyToMono(GoogleResponse.class))
.doOnError(e -> log.error("Request error"))
.subscribe(GoogleResponse -> {
try {
log.debug("Google response: {}", GoogleResponse);
if (!GoogleResponse.isSuccess()) {
throw new ReCaptchaInvalidException("reCaptcha response is not valid");
}
} catch (ReCaptchaInvalidException e) {
throw new ReCaptchaUnavailableException("Registration unavailable at this time. Please try again later.", e);
}
});