Fla*_*ski 5 project-reactor spring-webflux
如何使用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)
谢谢
return body.flatMap(str -> Mono.error(new WhateverException(str)));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2130 次 |
最近记录: |