I have a class like that:
@Override
public StudentDTO getStudent(@WebParam(name = "name") String studentName) {
StudentDTO student = new StudentDTO();
try {
student = studentService.findStudentByName(studentName);
} catch (Exception e) {
return new ErrorActionResponse("student couldn't find by name");
}
return student;
}
As usual this doesn’t work because of return type is StudentDTO and I try to return another type of class: ErrorActionResponse. ErrorActionResponse is an error class that has detailed information about error.
How can I design my web service architecture that can handle error situations? (At my REST architecture I write error information into response and send error to client side)
If you want to return a
Collection(as stated in a comment to my earlier answer), I suggest you create a Map with two keys. If there is no exception, first key-value pair will contain “students” string andStudentDTOcollection, respectively. And, second key-value pair will contain “exception” string and null value, respectively. If there is an exception, first key-value pair will contain “students” string and null value, respectively. And, second key-value pair will be “exception” string and anErrorActionResponseobject, respectively. Example:No exception case:
No exception case:
Hope this helps…