In Chapter 6, Dynamic 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 ...