From bd8c37c7375cc037254c2dec79b124baed9049dc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 14 Jul 2016 13:28:45 -0700 Subject: [PATCH] GUACAMOLE-5: Ensure all exceptions from within REST make their way to a JSON response, even if not a GuacamoleException. --- .../guacamole/rest/RESTExceptionWrapper.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/RESTExceptionWrapper.java b/guacamole/src/main/java/org/apache/guacamole/rest/RESTExceptionWrapper.java index 736907d4c..f4de4066b 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/RESTExceptionWrapper.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/RESTExceptionWrapper.java @@ -172,6 +172,11 @@ public class RESTExceptionWrapper implements MethodInterceptor { } + // Rethrow unchecked exceptions such that they are properly wrapped + catch (RuntimeException e) { + throw new GuacamoleException(e.getMessage(), e); + } + } // Additional credentials are needed @@ -267,17 +272,21 @@ public class RESTExceptionWrapper implements MethodInterceptor { // All other errors catch (GuacamoleException e) { - // Generate default message + // Log all reasonable details of exception String message = e.getMessage(); - if (message == null) - message = "Unexpected server error."; + if (message != null) + logger.error("Unexpected internal error: {}", message); + else + logger.error("An internal error occurred, but did not contain " + + "an error message. Enable debug-level logging for " + + "details."); - // Ensure internal errors are logged at the debug level + // Ensure internal errors are fully logged at the debug level logger.debug("Unexpected exception in REST endpoint.", e); throw new APIException( APIError.Type.INTERNAL_ERROR, - message + "Unexpected server error." ); }