web services - How to handle Internal Server Error in REST API using JAVA? -
i have create class handle runtime exception throws during service call , code
@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 data in xml format").build(); else if(response.getstatus()==403) return response.status(response.status.forbidden).entity("you not authorize access resource").build(); else if(response.getstatus()==500) return response.status(response.status.internal_server_error).entity("internal server error has occured.please check wheather have passed valid data or not").build(); else if(response.getstatus()==404) return response.status(response.status.not_found).entity("invalid url. please enter valid url").build(); else if(response.getstatus()==415) return response.status(response.status.unsupported_media_type).entity("invalid media type. please select correct media type").build(); else if(response.getstatus()==503) return response.status(response.status.service_unavailable).entity("server not available. please try after time").build(); else return response.status(response.status.ok).entity("").build(); }
my problem handles other exception throws during service calls except internal server error. please me how handle internal server error during run time in rest.
thanks in advance
i don't know webserver using, long adheres jee specs
handle in web.xml
:
<error-page>
<error-code>500</error-code>
<location>/path/to/myerrorpage.html</location>
</error-page>
Comments
Post a Comment