@@ -47,6 +47,7 @@ public class JreHttpUrlConnection implements Closeable {
47
47
* error.
48
48
*/
49
49
public static final String SQL_STATE_BAD_SERVER = "bad_server" ;
50
+ private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [/_xpack/sql] contains unrecognized parameter: [mode]" ;
50
51
51
52
public static <R > R http (String path , String query , ConnectionConfiguration cfg , Function <JreHttpUrlConnection , R > handler ) {
52
53
final URI uriPath = cfg .baseUri ().resolve (path ); // update path if needed
@@ -176,6 +177,19 @@ private <R> ResponseOrException<R> parserError() throws IOException {
176
177
}
177
178
SqlExceptionType type = SqlExceptionType .fromRemoteFailureType (failure .type ());
178
179
if (type == null ) {
180
+ // check if x-pack or sql are not available (x-pack not installed or sql not enabled)
181
+ // by checking the error message the server is sending back
182
+ if (con .getResponseCode () >= HttpURLConnection .HTTP_BAD_REQUEST
183
+ && failure .reason ().contains (SQL_NOT_AVAILABLE_ERROR_MESSAGE )) {
184
+ return new ResponseOrException <>(new SQLException ("X-Pack/SQL do not seem to be available"
185
+ + " on the Elasticsearch node using the access path '"
186
+ + con .getURL ().getHost ()
187
+ + (con .getURL ().getPort () > 0 ? ":" + con .getURL ().getPort () : "" )
188
+ + "'."
189
+ + " Please verify X-Pack is installed and SQL enabled. Alternatively, check if any proxy is interfering"
190
+ + " the communication to Elasticsearch" ,
191
+ SQL_STATE_BAD_SERVER ));
192
+ }
179
193
return new ResponseOrException <>(new SQLException ("Server sent bad type ["
180
194
+ failure .type () + "]. Original type was [" + failure .reason () + "]. ["
181
195
+ failure .remoteTrace () + "]" , SQL_STATE_BAD_SERVER ));
0 commit comments