title: ResponseEntityExceptionHandler returns empty response body for 401 exceptions
body: <p>I'm trying to implement a Rest call to an authentication server using RestTemplate and log the response in case the server returns an exception. In order to do this, I used a ResponseEntityExceptionHandler to handle HttpClientErrorException's and HttpServerErrorException's.</p>
  
  <pre><code>public Response sendRequest(Request requestBody, String url, HttpMethod httpMethod, Response responseBody) {
      RestTemplate restTemplate = new RestTemplate();
      HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt; request = new HttpEntity&lt;&gt;(requestBody.getBody(),
              this.securityHeaders);
      ResponseEntity&lt;? extends Response&gt; response = restTemplate.exchange(url, httpMethod, request,
              responseBody.getClass());
      return response.getBody();
  }
  </code></pre>
  
  <p>Currently my ResponseEntityExceptionHandler is the following</p>
  
  <pre><code>@ControllerAdvice
  public class RestResponseExceptionHandler extends ResponseEntityExceptionHandler {
  
  private static Logger log = LoggerFactory.getLogger(RestResponseExceptionHandler.class);
  private HttpHeaders headers = new HttpHeaders();
  
  @ExceptionHandler(value = { HttpClientErrorException.class, HttpServerErrorException.class })
  protected ResponseEntity&lt;Object&gt; handleConflict(HttpStatusCodeException ex, WebRequest request) {
      ErrorMessage responseBody = new ErrorMessage();
      try {
          JSONObject bodyOfException = new JSONObject(ex.getResponseBodyAsString());
          log.warn("{}| {}", ex.getStatusCode(), bodyOfException);
          responseBody.setErrorAndDescription(bodyOfException.optString("error"),
                  bodyOfException.optString("error_description"));
      } catch (JSONException e) {
          log.error("{}| Bad authentication response body | Response Body | {}", ex.getStatusCode(),
                  ex.getResponseBodyAsString());
      }
  
      return handleExceptionInternal(ex, responseBody, headers, ex.getStatusCode(), request);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However, only for HttpStatus 401 exceptions, I get an empty Response Body.</p>
  
  <p>Example of logs:</p>
  
  <pre><code>400| {"error_description":"Bad client credentials","error":"invalid_client"}
  
  401| Bad authentication response body | Response Body | 
  </code></pre>
  
  <p>Does anyone know how I can obtain the response body for 401 exceptions?</p>
  
  <p>Edit:
  When using a Postman to call the Authentication Server I get non null 401 responseBody:</p>
  
  <pre><code>{
   "error": "invalid_token",
   "error_description": "Token was not recognised"
  }
  </code></pre>