如何使用Mono.error(<Throwable>)从请求返回的正文中附加信息?
Throwable了一个 Mono/Flux 对象,因此抛出的错误将等待主体被考虑?Throwable)下面的示例场景:
import org.springframework.web.reactive.function.client.WebClient;
private someMethod() {
webClient.get().retrieve().onStatus(HttpStatus::isError, this::errorHandler)
}
Run Code Online (Sandbox Code Playgroud)
private Mono<? extends Throwable> errorHandler(ClientResponse cr) {
Mono<String> body = cr.body(BodyExtractors.toMono(String.class));
...<do something here>...
return Mono.error(new WhateverException());
}
Run Code Online (Sandbox Code Playgroud)
谢谢