【问题标题】:How to handle standard status with Spring WebClient?如何使用 Spring WebClient 处理标准状态?
【发布时间】:2019-09-24 16:14:53
【问题描述】:

我想以同样的方式处理标准的 http 错误。我如何使用 Spring WebClient 做到这一点?而不是在下面的每个呼叫上挂起状态检查

webClient.get()
    .uri("http://localhost:8081/resource")
    .retrieve()
    .onStatus(HttpStatus::isError, clientResponse -> {
        // some error handling logic
    })
    .bodyToMono(MyPojo.class);

【问题讨论】:

  • 如果您的webClientsingleton,您可以在创建bean 时将ExchangeFilterFunction.ofResponseProcessor 过滤器添加到webclient,您可以在其中为所有webservice 调用编写常见的错误处理逻辑。

标签: spring spring-webflux spring-webclient


【解决方案1】:

基于@akreddy.21 评论的解决方案

在创建 bean 时将 ExchangeFilterFunction.ofResponseProcessor 过滤器添加到 webclient,您可以在其中为所有 webservice 调用编写常见的错误处理逻辑。

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 2020-06-03
    • 1970-01-01
    • 2021-10-25
    • 2021-12-14
    • 2021-08-06
    • 2022-07-10
    • 2020-11-04
    • 2017-09-22
    相关资源
    最近更新 更多