Return speciefic error messages from server implementation
<p>I am developing a web server in java as part of my study; the server has model logic.</p>

<p>I am looking for method to send specific error messages to the client. To do so, the deeper layer of the logic should return some class with the error.</p>

<p>The current implementation is like that:</p>

<p><code>BaseResponse</code> - abstract class that all other response inherit from it.
<code>ErrorResponse</code> - this is the response class that has the specific error message.</p>

<p>This method is very limiting, because if in the upper layers of the logic I want to see if the request was successful or not, I should check the type, and then cast the response to the correct class.</p>

<p>for example:</p>

<ol>
<li>layer 1: <code>ServiceApi.login(username, pass)</code></li>
<li>layer 2: <code>system.login(username, pass)</code></li>
<li>layer 3: <code>userManager.login(username, pass)</code></li>
</ol>

<p>the <code>userManager</code> is the one that actually does the login logic, then if I in layer 2 want to check if it was successful or not, I should do the casting and instance checking.</p>

<p>so, I am looking for method that in the layers I will get the object themselves (and not response) and still for the client return the specific error messages.</p>
