title: How to handle errors from web service
body: <p>Sorry I am new to Spring and Java and this may be covered lots of times but I wanted to get some advice. </p>
  
  <p>I'm creating a Spring web application which needs to retrieve user data from an existing REST based XML web service. I am going to create a domain object, service and DAO which uses the Spring REST template to invoke the web service. </p>
  
  <p>In the DAO I was going to create a method like this:</p>
  
  <pre><code>public User getUser(String userId)
  </code></pre>
  
  <p>If there is a problem (for example if the user account is locked or been deleted), the web service returns a 200 response and puts an error code in the XML response. These errors should be displayed in the application and I will need to be able to identify the error so I can show custom error message to the user. What is the recommended way to handle these error, should I:</p>
  
  <ol>
  <li>Define different exceptions (runtime) for each of the error response codes and add these to the method signature</li>
  <li>Use a single exception (e.g. UserException) and use different messages. </li>
  <li>Do something else</li>
  </ol>
  
  <p>Any help would be highly appreciated.</p>