title: Returning Mono and Flux error always returns 500
body: <p>I'm still trying to learn how WebFlux exceptions work, as far as I understand, when returning an object in a Flux or Mono, the consumer should receive the same exception which was sent from the server.</p>
  <p>However, when I return an HTTPException 401 inside a Mono for example, the response body I receive in the consumer is different from what I sent, I read a 500 Internal Server error instead of 401.</p>
  <p>Here is a simple controller class I made for the question</p>
  <pre><code>package com.example.demo;
  
  import javax.xml.ws.http.HTTPException;
  
  import org.springframework.http.MediaType;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  import reactor.core.publisher.Mono;
  
  @RestController
  public class Controller {
  
  @RequestMapping(
          path=&quot;/getExceptionMono&quot;,
          method = RequestMethod.GET,
          produces = MediaType.APPLICATION_JSON_VALUE)
      public Mono&lt;String&gt; getException(){
          return Mono.error(new HTTPException(401));
      }
  }
  </code></pre>
  <p>Here is the consumer :</p>
  <pre><code>package com.example.demo;
  
  import org.springframework.boot.CommandLineRunner;
  import org.springframework.http.MediaType;
  import org.springframework.stereotype.Component;
  import org.springframework.web.reactive.function.client.WebClient;
  
  @Component
  public class ReactiveDemoConsumer implements CommandLineRunner {
      @Override
      public void run(String... args) throws Exception {
          String url = &quot;http://localhost:8080/getExceptionMono&quot;;
          WebClient.create(url)
              .get()
              .accept(MediaType.APPLICATION_JSON)
              .retrieve()
              .bodyToMono(String.class)
              .subscribe(value -&gt; System.err.println(&quot;Received String: &quot; + value),
                          err -&gt; System.err.println(&quot;Received error &quot; + err));
  
      }
  }
  </code></pre>
  <p>This is the console log of the consumer</p>
  <pre><code>Received error org.springframework.web.reactive.function.client.WebClientResponseException$InternalServerError: 500 Internal Server Error from GET http://localhost:8080/getExceptionMono
  </code></pre>
  <p>How do I pass my exception so that the consumer will see the original one which I passed in the Mono?
  Hope my question is clear, thanks in advance</p>