use of com.peterphi.std.guice.web.rest.jaxrs.exception.RestFailureMarshaller in project stdlib by petergeneric.
the class GuicedResteasy method tryHandleException.
/**
* @param ctx
* @param response
* @param t
*
* @throws ServletException
* @throws IOException
* @throws RuntimeException
* @throws Error
*/
private void tryHandleException(HttpCallContext ctx, HttpServletResponse response, Throwable t) throws ServletException, IOException, RuntimeException, Error {
if (suppressClientAbortExceptions && t instanceof UnhandledException && t.getCause() != null) {
// Only look 20 exceptions deep
int maxDepth = 20;
Throwable cause = t.getCause();
while (cause != null && --maxDepth > 0) {
if (cause.getClass().getName().equals("org.apache.catalina.connector.ClientAbortException")) {
ignoredAborts.mark();
if (log.isTraceEnabled())
log.trace("Client aborted during request. Ignoring. Detail: " + ctx.getRequestInfo(), t);
return;
} else {
cause = cause.getCause();
}
}
}
log.warn("Failure during " + ctx.getRequestInfo(), t);
// If the response is already committed we can't render the exception elegantly
if (response.isCommitted())
rethrow(t);
try {
RestFailureMarshaller marshaller = new RestFailureMarshaller();
RestFailure failure = marshaller.renderFailure(t);
TwitterBootstrapRestFailurePageRenderer renderer = new TwitterBootstrapRestFailurePageRenderer(failure);
// internal error
response.setStatus(500);
// Render the HTML
final StringBuilder sb = new StringBuilder(4096);
renderer.writeHTML(sb);
response.getWriter().print(sb);
} catch (Throwable newException) {
log.warn("Error trying to present exception elegantly: ", newException);
// Rethrow the original exception, it's not our problem anymore
rethrow(t);
}
}
Aggregations