相关文章推荐
才高八斗的双杠  ·  MSSQLSERVER_18452 - ...·  1 年前    · 
眼睛小的鸭蛋  ·  ALTER TABLE ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using Webflux to make a Flux of concurrent requests via proxy to a web server. Depending on the proxy, sometimes the connection fails. I would like to catch these errors and handle them (ideally by returning an empty Mono object)

2019-02-17 16:48:19.947 ERROR 32265 --- [or-http-epoll-8] r.n.resources.PooledConnectionProvider   : [id: 0xf7c8834b, L:/192.168.2.247:45536 - R:101.248.64.72/101.248.64.72:80] Pooled connection observed an error
io.netty.handler.proxy.ProxyConnectException: http, none, /101.248.64.72:80 => domain.com:443, io.netty.channel.unix.Errors$NativeIoException: syscall:read(..) failed: Connection reset by peer
at io.netty.handler.proxy.ProxyHandler.setConnectFailure(ProxyHandler.java:344) [netty-handler-proxy-4.1.31.Final.jar:4.1.31.Final]
at io.netty.handler.proxy.ProxyHandler.exceptionCaught(ProxyHandler.java:246) [netty-handler-proxy-4.1.31.Final.jar:4.1.31.Final]

These messages are very long and make the log unreadable later on if debugging is required. I've tried catching it in line with the request code by using .onErrorResume(err -> Mono.empty()) but it doesn't seem to prevent the error logs.

Below is my code:

return proxiedWebClient
    .get()
    .uri(uri)
    .exchange()
    .flatMap(clientResponse -> clientResponse.toEntity(String.class))
    .onErrorResume(error -> Mono.empty());

The expected result is that connection errors are simply dropped and not added into the Flux when Flux.merge is subsequently called.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.