@Override
  protected void writeErrorPageStacks(HttpServletRequest request, Writer writer)
    throws IOException {
    Throwable th = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);

    while (th != null) {
      writer.write("Caused by:\n");
      write(writer, ExceptionUtils.getStackTrace(th));
      writer.write("\n");
      th = th.getCause();
    }
  }
Custom error handler for Jetty to return response as JSON instead of stub http page
ambari-server/src/main/java/org/apache/ambari/server/api/AmbariErrorHandler.java