I am getting Internal Server Error on postman even though I am throwing custom exception from my code exception. I want to see the exception having valid error message and error code, what I am throwing. It will be a great help if anyone of you can help me on this point. Like how I can get better error message. Adding below code snap. Thanks in advance
@Service
public class FetchActionImpl implements FetchAction {
private static Logger log = LoggerFactory.getLogger(FetchActionImpl.class);
@Autowired
FetchActionServiceImpl fetchActionService;// = new FetchActionServiceImpl();
@Override
public FetchResponse fetchActionRequest(String caseId) throws BBWException,Exception{
//String resp ="";
log.info("fetchaction Request: {}",ApplicationConstants.LOG_ENTRY_MESSAGE);
log.info("The caseId received from BRASS:\n {}",caseId);
FetchResponse resp = null;
try{
if(true) {
throw new BBWException("500","Test");
}
resp = fetchActionService.fetchIt(caseId);
log.debug("fetchaction Response: {}",resp.toString());
}
catch (BBWException be) {
throw be;
}
catch (Exception e) {
throw new BBWException("500",e.getMessage());
}
return resp;
}
}
@Api
@Path("/fetch_service")
public interface FetchAction {
@GET
@Path("/fetchaction/caseid/{caseid}")
@Produces({MediaType.APPLICATION_JSON})
//@Consumes({MediaType.TEXT_XML})
@ApiOperation(
value = "Respond BRASS Request",
notes = "Returns a XML object "
)
@ApiResponses(
value = {
@ApiResponse(code = 404, message = "Service not available"),
@ApiResponse(code = 500, message = "Unexpected Runtime error")
})
public FetchResponse fetchActionRequest(@PathParam("caseid") String caseid) throws BBWException, Exception;
}`
public class BBWException extends Exception {
private static final long serialVersionUID = -7987978270260338068L;
private String errorCode;
private String errorMessage;
public BBWException(String errorCode, String errorMessage) {
super(errorMessage);
this.errorCode = errorCode;
this.errorMessage = errorMessage;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
@Override
public String toString() {
return (this.errorCode + " " + this.errorMessage);
}
}