【发布时间】:2019-12-09 09:45:23
【问题描述】:
我尝试使用 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);
}
});
【问题讨论】:
标签: java spring-boot spring-webclient