title: RestTemplate - Handling response headers/body in Exceptions (RestClientException, HttpStatusCodeException)
body: <p>In my restful webservice, in case of bad request (5xx) or 4xx respose codes, I write a custom header "x-app-err-id" to the response.</p>
  
  <p>On the client side, I use exchange method of RestTemplate to make a RestFul web service call. Everything is fine when the response code is 2xx. </p>
  
  <pre class="lang-java prettyprint-override"><code>ResponseEntity&lt;Component&gt; response = restTemplate.exchange(webSvcURL,
      HttpMethod.POST, 
      requestEntity,
      Component.class);
  </code></pre>
  
  <p>But if there is an exception(HttpStatusCodeException) because of it being a bad request(5xx) or 4xx, in the catch block of HttpStatusCodeException, I get response(see above) as null and so I do not have access to my custom header I set in my web service.  How do I get custom headers from the response in case of exceptions in RestTemplate. </p>
  
  <p>One more question is, I set an error object(json) in the reponse body in case of error and I would like to know how to access response body as well in case of exceptions in RestTemplate</p>