异常处理反应

Exception Handling Reactive

如何使用 Mono.error(<Throwable>) 但从请求返回的正文附加信息?

下面的示例场景:

import org.springframework.web.reactive.function.client.WebClient;

private someMethod() {
    webClient.get().retrieve().onStatus(HttpStatus::isError, this::errorHandler)
}

private Mono<? extends Throwable> errorHandler(ClientResponse cr) {
    Mono<String> body = cr.body(BodyExtractors.toMono(String.class));

        ...<do something here>...

    return Mono.error(new WhateverException());
}

谢谢

return body.flatMap(str -> Mono.error(new WhateverException(str)));