protected void doUnexpectedFailure(Throwable e) {
// logger les erreurs
logger.error("Erreur inattendu", e);
if( e != null && e.getCause() instanceof ServiceException ) {
ServiceException serviceException = (ServiceException) e.getCause();
try {
getThreadLocalResponse().reset();
}
catch( IllegalStateException ex ) {
throw new RuntimeException("Unable to report failure", serviceException);
}
ServletContext servletContext = getServletContext();
HttpServletResponse response = getThreadLocalResponse();
try {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
try {
response.getOutputStream().write(serviceException.getCode().getBytes());
}
catch( IllegalStateException ex ) {
response.getWriter().write(serviceException.getCode());
}
}
catch( IOException ex ) {
servletContext.log(
"respondWithUnexpectedFailure failed while sending the previous failure to the client", ex);