SQL: handle X-Pack or X-Pack SQL not being available in a more graceful way (#34736)
Throw a different error message for a http response code of 400, but also when the error itself is of a specific type.
This commit is contained in:
parent
d6dc62ef03
commit
a7e08f462f
|
@ -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> R http(String path, String query, ConnectionConfiguration cfg, Function<JreHttpUrlConnection, R> handler) {
|
||||
final URI uriPath = cfg.baseUri().resolve(path); // update path if needed
|
||||
|
@ -176,6 +177,19 @@ public class JreHttpUrlConnection implements Closeable {
|
|||
}
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue