CaTz
CaTz

Reputation: 315

Return speciefic error messages from server implementation

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:

  1. layer 1: ServiceApi.login(username, pass)
  2. layer 2: system.login(username, pass)
  3. layer 3: 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

Answers (1)

Related Questions