Spring Webflux : Webclient : Get body on error

后端 未结 8 2267
失恋的感觉
失恋的感觉 2021-02-05 09:04

I am using the webclient from spring webflux, like this :

WebClient.create()
            .post()
            .uri(url)
            .syncBody(body)
            .a         


        
8条回答
  •  你的背包
    2021-02-05 09:33

    We have finally understood what is happening : By default the Netty's httpclient (HttpClientRequest) is configured to fail on server error (response 5XX) and not on client error (4XX), this is why it was always emitting an exception.

    What we have done is extend AbstractClientHttpRequest and ClientHttpConnector to configure the httpclient behave the way the want and when we are invoking the WebClient we use our custom ClientHttpConnector :

     WebClient.builder().clientConnector(new CommonsReactorClientHttpConnector()).build();
    

提交回复
热议问题