diff --git a/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/JreHttpUrlConnection.java b/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/JreHttpUrlConnection.java index 0dca4a88f0592..3f894ae59af8e 100644 --- a/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/JreHttpUrlConnection.java +++ b/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/JreHttpUrlConnection.java @@ -47,6 +47,7 @@ public class JreHttpUrlConnection implements Closeable { * error. */ public static final String SQL_STATE_BAD_SERVER = "bad_server"; + private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [/_xpack/sql] contains unrecognized parameter: [mode]"; public static R http(String path, String query, ConnectionConfiguration cfg, Function handler) { final URI uriPath = cfg.baseUri().resolve(path); // update path if needed @@ -176,6 +177,19 @@ private ResponseOrException parserError() throws IOException { } SqlExceptionType type = SqlExceptionType.fromRemoteFailureType(failure.type()); if (type == null) { + // check if x-pack or sql are not available (x-pack not installed or sql not enabled) + // by checking the error message the server is sending back + if (con.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST + && failure.reason().contains(SQL_NOT_AVAILABLE_ERROR_MESSAGE)) { + return new ResponseOrException<>(new SQLException("X-Pack/SQL do not seem to be available" + + " on the Elasticsearch node using the access path '" + + con.getURL().getHost() + + (con.getURL().getPort() > 0 ? ":" + con.getURL().getPort() : "") + + "'." + + " Please verify X-Pack is installed and SQL enabled. Alternatively, check if any proxy is interfering" + + " the communication to Elasticsearch", + SQL_STATE_BAD_SERVER)); + } return new ResponseOrException<>(new SQLException("Server sent bad type [" + failure.type() + "]. Original type was [" + failure.reason() + "]. [" + failure.remoteTrace() + "]", SQL_STATE_BAD_SERVER));