Reputation: 315
I am developing a web server in java as part of my study; the server has model logic.
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.
The current implementation is like that:
BaseResponse
- abstract class that all other response inherit from it.
ErrorResponse
- this is the response class that has the specific error message.
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.
for example:
ServiceApi.login(username, pass)
system.login(username, pass)
userManager.login(username, pass)
the userManager
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.
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.
Upvotes: 0
Views: 392
Reputation: 80194
You can do it multiple ways
Also read Exception handling best practices.
Upvotes: 1