예제 #1
0
  public void handleException(HttpRequest request, HttpResponse response, Throwable e) {
    // See if there is an ExceptionMapper for the exact class of the exception instance being thrown
    if (executeExactExceptionMapper(request, response, e)) return;

    // These are wrapper exceptions so they need to be processed first as they map e.getCause()
    if (e instanceof ApplicationException) {
      handleApplicationException(request, response, (ApplicationException) e);
      return;
    } else if (e instanceof WriterException) {
      handleWriterException(request, response, (WriterException) e);
      return;
    } else if (e instanceof ReaderException) {
      handleReaderException(request, response, (ReaderException) e);
      return;
    }

    // First try and handle it with a mapper
    if (executeExceptionMapper(request, response, e)) {
      return;
    }
    // Otherwise do specific things
    else if (e instanceof WebApplicationException) {
      handleWebApplicationException(request, response, (WebApplicationException) e);
    } else if (e instanceof Failure) {
      handleFailure(request, response, (Failure) e);
    } else {
      logger.error(
          "Unknown exception while executing "
              + request.getHttpMethod()
              + " "
              + request.getUri().getPath(),
          e);
      throw new UnhandledException(e);
    }
  }
예제 #2
0
  protected Throwable unwrapException(HttpRequest request, HttpResponse response, Throwable e) {
    Throwable unwrappedException = e.getCause();

    if (executeExceptionMapper(request, response, unwrappedException)) {
      return null;
    }
    if (unwrappedException instanceof WebApplicationException) {
      handleWebApplicationException(
          request, response, (WebApplicationException) unwrappedException);
      return null;
    } else if (unwrappedException instanceof Failure) {
      handleFailure(request, response, (Failure) unwrappedException);
      return null;
    } else {
      if (unwrappedExceptions.contains(unwrappedException.getClass().getName())
          && unwrappedException.getCause() != null) {
        return unwrapException(request, response, unwrappedException);
      } else {
        return unwrappedException;
      }
    }
  }