/** * Handles the given exception by selecting the appropriate error code, status code and * to-be-exposed arguments conditionally. * * @param exception The exception to handle. * @return The handled exception. */ @NonNull @Override public HandledException handle(Throwable exception) { List<String> arguments = null; String errorCode = "unknown_error"; if (exception instanceof MissingRequestHeaderException) { arguments = singletonList(((MissingRequestHeaderException) exception).getHeaderName()); errorCode = MISSING_HEADER; } else if (exception instanceof MissingRequestCookieException) { arguments = singletonList(((MissingRequestCookieException) exception).getCookieName()); errorCode = MISSING_COOKIE; } else if (exception instanceof MissingMatrixVariableException) { arguments = singletonList(((MissingMatrixVariableException) exception).getVariableName()); errorCode = MISSING_MATRIX_VARIABLE; } return new HandledException(errorCode, BAD_REQUEST, singletonMap(errorCode, arguments)); } }