GUACAMOLE-5: Ensure all exceptions from within REST make their way to a JSON response, even if not a GuacamoleException.

This commit is contained in:
Michael Jumper
2016-07-14 13:28:45 -07:00
parent 6e81a20185
commit bd8c37c737

View File

@@ -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 // Additional credentials are needed
@@ -267,17 +272,21 @@ public class RESTExceptionWrapper implements MethodInterceptor {
// All other errors // All other errors
catch (GuacamoleException e) { catch (GuacamoleException e) {
// Generate default message // Log all reasonable details of exception
String message = e.getMessage(); String message = e.getMessage();
if (message == null) if (message != null)
message = "Unexpected server error."; 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); logger.debug("Unexpected exception in REST endpoint.", e);
throw new APIException( throw new APIException(
APIError.Type.INTERNAL_ERROR, APIError.Type.INTERNAL_ERROR,
message "Unexpected server error."
); );
} }