title: Spring WebClient - how to access response body in case of HTTP errors (4xx, 5xx)?
body: <p>I want to re-throw my exception from my "Database" REST API to my "Backend" REST API but I lose the original exception's message.</p>
  
  <p>This is what i get from my "Database" REST API via Postman:</p>
  
  <pre><code>{
      "timestamp": "2020-03-18T15:19:14.273+0000",
      "status": 400,
      "error": "Bad Request",
      "message": "I'm DatabaseException (0)",
      "path": "/database/api/vehicle/test/0"
  }
  </code></pre>
  
  <p>This part is ok.</p>
  
  <p>This is what i get from my "Backend" REST API via Postman:</p>
  
  <pre><code>{
      "timestamp": "2020-03-18T15:22:12.801+0000",
      "status": 400,
      "error": "Bad Request",
      "message": "400 BAD_REQUEST \"\"; nested exception is org.springframework.web.reactive.function.client.WebClientResponseException$BadRequest: 400 Bad Request from GET http://localhost:8090/database/api/vehicle/test/0",
      "path": "/backend/api/vehicle/test/0"
  }
  </code></pre>
  
  <p>As you can see the original "message" field is lost.</p>
  
  <p>I use:</p>
  
  <ul>
  <li>Spring boot 2.2.5.RELEASE</li>
  <li>spring-boot-starter-web</li>
  <li>spring-boot-starter-webflux</li>
  </ul>
  
  <p>Backend and Database start with Tomcat (<a href="https://stackoverflow.com/questions/51377675/does-not-the-spring-boot-starter-web-and-spring-boot-starter-webflux-work-togeth">web and webflux in the same application</a>).</p>
  
  <p>This is Backend:</p>
  
  <pre><code>    @GetMapping(path = "/test/{id}")
      public Mono&lt;Integer&gt; test(@PathVariable String id) {
          return vehicleService.test(id);
      }
  </code></pre>
  
  <p>With vehicleService.test:</p>
  
  <pre><code>    public Mono&lt;Integer&gt; test(String id) {
          return WebClient
              .create("http://localhost:8090/database/api")
              .get()
              .uri("/vehicle/test/{id}", id)
              .accept(MediaType.APPLICATION_JSON)
              .retrieve()
              .bodyToMono(Integer.class);
      }
  </code></pre>
  
  <p>This is Database:</p>
  
  <pre><code>    @GetMapping(path = "/test/{id}")
      public Mono&lt;Integer&gt; test(@PathVariable String id) throws Exception {
  
          if (id.equals("0")) {
              throw new DatabaseException("I'm DatabaseException (0)");
          }
  
          return Mono.just(Integer.valueOf(2));
      }
  </code></pre>
  
  <p>I also tried with <code>return Mono.error(new DatabaseException("I'm DatabaseException (0)"));</code></p>
  
  <p>And DatabaseException:</p>
  
  <pre><code>public class DatabaseException extends ResponseStatusException {
  
      private static final long serialVersionUID = 1L;
  
      public DatabaseException(String message) {
          super(HttpStatus.BAD_REQUEST, message);
  
      }
  }
  </code></pre>
  
  <p>It seems my Backend transforms the response and can't find any answer on internet.</p>