I have create a class to handle runtime exception throws during service call and my code is
@Override
public Response toResponse(WebApplicationException exception) {
Response response=exception.getResponse();
if(response.getStatus()==400)
return Response.status(Response.Status.BAD_REQUEST).entity("Invalid data format. Please enter the data in xml format").build();
else if(response.getStatus()==403)
return Response.status(Response.Status.FORBIDDEN).entity("You are not authorize to access this resource").build();
else if(response.getStatus()==500)
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Internal server error has occured.Please check wheather you have passed valid data or not").build();
else if(response.getStatus()==404)
return Response.status(Response.Status.NOT_FOUND).entity("Invalid url. Please enter a valid url").build();
else if(response.getStatus()==415)
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity("Invalid media type. Please select the correct media type").build();
else if(response.getStatus()==503)
return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("Server is not available. Please try after some time").build();
else
return Response.status(Response.Status.OK).entity("").build();
}
my problem is that it handles all the other exception throws during service calls except INTERNAL SERVER ERROR. Please help me how to handle INTERNAL SERVER ERROR during run time in REST.
Thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…