title: How to do Exception Handling for WebFlux using Springboot?
body: <p>I have 3 micro-service applications. I am trying to do 2 get call async using webclient from reactive package and then combine them whenever I get a response.</p>
  
  <p>Sample code for that:
  (referred from - <a href="https://docs.spring.io/spring/docs/5.1.9.RELEASE/spring-framework-reference/web-reactive.html#webflux-client-synchronous" rel="nofollow noreferrer">https://docs.spring.io/spring/docs/5.1.9.RELEASE/spring-framework-reference/web-reactive.html#webflux-client-synchronous</a>)</p>
  
  <pre><code>Mono&lt;Person&gt; personMono = client.get().uri("/person/{id}", personId)
          .retrieve().bodyToMono(Person.class);
  
  Mono&lt;List&lt;Hobby&gt;&gt; hobbiesMono = client.get().uri("/person/{id}/hobbies", personId)
          .retrieve().bodyToFlux(Hobby.class).collectList();
  
  Map&lt;String, Object&gt; data = Mono.zip(personMono, hobbiesMono, (person, hobbies) -&gt; {
              Map&lt;String, String&gt; map = new LinkedHashMap&lt;&gt;();
              map.put("person", personName);
              map.put("hobbies", hobbies);
              return map;
          })
          .block();
  </code></pre>
  
  <p>My question is how can I add exception handling to the get calls?</p>
  
  <p>How do I check if I got a 404 or 204 or something else?</p>
  
  <p>I have tried:</p>
  
  <ol>
  <li>Adding .onStatus()  to the GET calls</li>
  </ol>
  
  <pre><code>    .onStatus(HttpStatus::is4xxClientError, clientResponse -&gt;
               Mono.error(new Data4xxException(String.format(
                  "Could not GET data with id: %s from another app, due to error: 
                   %s", key, clientResponse))))
      .onStatus(HttpStatus::is5xxServerError, clientResponse -&gt;
            Mono.error(new Data5xxException(
                String.format("For Data %s, Error Occurred: %s", key, clientResponse))))
  </code></pre>
  
  <ol start="2">
  <li>Adding exceptionhandlers - but I exactly dont have a controller so this does not seem to be working.</li>
  </ol>
  
  <pre><code>@ExceptionHandler(WebClientException.class)
      public Exception handlerWebClientException(WebClientException webClientException) {
          return new Data4xxException("Testing", webClientException);
      }
  </code></pre>
  
  <ol start="3">
  <li>Added a class with ControllerAdvice and ExceptionHandler within it</li>
  </ol>
  
  <pre><code>@ControllerAdvice
  public class WebFluxExceptionHandler {
  
      @ExceptionHandler(WebClientException.class)
      public Exception handlerWebClientException(WebClientException webClientException) {
          return new Data4xxException("Testing", webClientException);
      }
  }
  </code></pre>
  
  <p>But I don't see them printed in the spring-boot logs.</p>
  
  <p>The Mono.zip.block() method just returns null and does not actually throw any exception.</p>
  
  <p><strong>How do I get the zip method to throw the exception and not return null ?</strong></p>