title: Why is my error message body missing in the client exception while using RestTemplate in Java?
body: <p>I am calling a method called revoke in my project which in turn uses rest template to make http calls.</p>
  
  <pre><code>public revoke(String name){ 
     try{
      restTemplate.exchange(approveRevokeRequestEntity, String.class);
      }
  catch (Exception e) {
          throw new ProcessException("Error while revoking!", e);
      }
  }
  </code></pre>
  
  <p>This in called somewhat as follows:</p>
  
  <pre><code>try {
          client.revoke(name);
      }
  catch (ProcessException e)   {
  
       log.info("Error Message is: {}",e.getMessage());   
       log.info("Cause Message is: {}",e.getCause().getMessage()); 
       if(e.getCause().getMessage().contains("already_revoked")) {
              log.info("Revoke request threw and Exception with expected cause, Continuing!")        
          }
          else {
              throw e;
          }
  }
  </code></pre>
  
  <p>I know this throws exceptions for non 2xx response codes.</p>
  
  <p>When I run this in locally in my IDE for a negative scenario, I get the following logs:</p>
  
  <pre><code>20:14:55.743 Error Message is: Error while revoking!
  20:14:55.743 Cause Message is: 400 Bad Request: [{"errors":[{"code":"already_revoked","message":"Already been revoked."}]}]
  20:14:55.743 Revoke request threw and Exception with expected cause, Continuing!
  </code></pre>
  
  <p>When I run this on the server, I get the status ("400 Bad Request") in the cause but the response body ("{"errors":[{"code":"already_revoked"....) is <strong>missing</strong>. As a result, the ".contains("already_revoked")" returns <strong>false</strong>, and instead of proceeding, the code terminates the process.</p>
  
  <pre><code>20:14:55.743 Error Message is: Error while revoking!
  20:14:55.743 Cause Message is: 400 Bad Request
  </code></pre>
  
  <p>I am calling the same endpoint with the same credentials in both my local test and on the server. Not sure why I am not getting the error response body in the cause. </p>
  
  <p>I even tried adding the following to my rest template but no success.</p>
  
  <pre><code>MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(new ObjectMapper());
  restTemplateForDigiCert.getMessageConverters().add(converter);
  </code></pre>
  
  <p>This is holding up my release, really need help here. 
  Thanks!</p>