How can I disable the default response body when Jetty catches an exception and returns an error? I am not using any XML or WAR and I don't want to add any.
I prefer to avoid doing a try { // Servlet code } catch (Exception e) { resp.setStatus(500) }
in every servlet.
If I don't do that, Jetty will return a 500 response with a body that specifies the stack trace. If a not found endpoint is reached, Jetty will return a 404 response with a body that says "Powered by Jetty". I want to remove those bodies and just keep the response code.
This is the code that starts my Jetty server:
private static void startServer() throws Exception {
final org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(7070);
final WebAppContext context = new WebAppContext("/", "/");
context.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebInfConfiguration() });
context.setExtraClasspath("build/classes/main/com/example");
server.setHandler(context);
server.start();
server.join();
}