O'Reilly logo

Hands-On Reactive Programming with Reactor by Rahul Sharma

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WebClient

In Chapter 6Dynamic Rendering, we discussed using the Spring WebClient to make web calls in a non-blocking and asynchronous manner. The operators that we have discussed so far are applicable to Reactive Stream publishers and subscribers. WebClient also produces a Mono publisher of ServerResponse. So, how should we handle errors generated in WebClient, and generate a valid response? First, let's take a look at WebClient's default handling of server-side errors. To do this, we should first generate errors in our Fibonacci handler function, as follows:

   @Bean    RouterFunction<ServerResponse> fibonacciEndpoint() {        Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,                Long>of(0L, 1L), (state, sink) -> { throw new RuntimeException("Method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required