title: How to handle error responses using spring rest client
body: <p>I am trying to better handle bad responses when using the sprint rest client.  My code is as follows:</p>
  
  <pre><code>ResponseEntity&lt;Foo&gt; response = null;
  
  try {
      response = restTemplate.exchange(uri, HttpMethod.GET,
                         new HttpEntity&lt;&gt;(new HttpHeaders()), Foo.class);
  catch (RestClientException rce) {
      //what to do here?
  } 
  </code></pre>
  
  <p>This works great as long as there is no error.  The problem is that when the corresponding web service returns an error (or times out), I just get an exception.  There is no enum with a status code where I could handle it as I wish.  Sometimes the error message is useful. Sometimes not.  Usually, if the corresponding server returns an html error page, I just get a message that the object cannot be created, but the specific error is swallowed.</p>
  
  <p>Any ideas?</p>