Skip to content

Commit 8d98042

Browse files
committed
[Gem] Updates error for unsupported Elasticsearch
1 parent 35ee41b commit 8d98042

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

elasticsearch/lib/elasticsearch.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
module Elasticsearch
2323
SECURITY_PRIVILEGES_VALIDATION_WARNING = 'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.'.freeze
2424
NOT_ELASTICSEARCH_WARNING = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'.freeze
25+
NOT_SUPPORTED_ELASTICSEARCH_WARNING = 'The client noticed that the server is not a supported distribution of Elasticsearch.'.freeze
2526
YOU_KNOW_FOR_SEARCH = 'You Know, for Search'.freeze
2627

2728
class Client
@@ -66,23 +67,22 @@ def verify_elasticsearch
6667
end
6768

6869
def verify_with_version_or_header(body, version, headers)
69-
raise Elasticsearch::NotElasticsearchError if version.nil? || version < '6.0.0'
70+
raise Elasticsearch::UnsupportedProductError if version.nil? || version < '6.0.0'
7071

7172
if version == '7.x-SNAPSHOT' || Gem::Version.new(version) >= Gem::Version.new('7.14-SNAPSHOT')
72-
raise Elasticsearch::NotElasticsearchError unless headers['x-elastic-product'] == 'Elasticsearch'
73+
raise Elasticsearch::UnsupportedProductError unless headers['x-elastic-product'] == 'Elasticsearch'
7374

7475
@verified = true
7576
elsif Gem::Version.new(version) > Gem::Version.new('6.0.0') &&
7677
Gem::Version.new(version) < Gem::Version.new('7.0.0')
77-
raise Elasticsearch::NotElasticsearchError unless
78+
raise Elasticsearch::UnsupportedProductError unless
7879
body['tagline'] == YOU_KNOW_FOR_SEARCH
7980

8081
@verified = true
8182
elsif Gem::Version.new(version) >= Gem::Version.new('7.0.0') &&
8283
Gem::Version.new(version) < Gem::Version.new('7.14-SNAPSHOT')
83-
raise Elasticsearch::NotElasticsearchError unless
84-
body['tagline'] == YOU_KNOW_FOR_SEARCH &&
85-
body.dig('version', 'build_flavor') == 'default'
84+
raise Elasticsearch::UnsupportedProductError unless body['tagline'] == YOU_KNOW_FOR_SEARCH
85+
raise Elasticsearch::UnsupportedProductError.new(NOT_SUPPORTED_ELASTICSEARCH_WARNING) unless body.dig('version', 'build_flavor') == 'default'
8686

8787
@verified = true
8888
end
@@ -93,9 +93,9 @@ def elasticsearch_validation_request
9393
end
9494
end
9595

96-
class NotElasticsearchError < StandardError
97-
def initialize
98-
super(NOT_ELASTICSEARCH_WARNING)
96+
class UnsupportedProductError < StandardError
97+
def initialize(message = NOT_ELASTICSEARCH_WARNING)
98+
super(message)
9999
end
100100
end
101101
end

elasticsearch/spec/unit/elasticsearch_product_validation_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
{ 'content-type' => 'json' }
3636
end
3737

38-
def error_requests_and_expectations
39-
expect { client.count }.to raise_error Elasticsearch::NotElasticsearchError
38+
def error_requests_and_expectations(message = Elasticsearch::NOT_ELASTICSEARCH_WARNING)
39+
expect { client.count }.to raise_error Elasticsearch::UnsupportedProductError, message
4040
assert_requested :get, host
4141
assert_not_requested :post, "#{host}/_count"
42-
expect { client.cluster.health }.to raise_error Elasticsearch::NotElasticsearchError
42+
expect { client.cluster.health }.to raise_error Elasticsearch::UnsupportedProductError, message
4343
expect(client.instance_variable_get('@verified')).to be false
44-
expect { client.cluster.health }.to raise_error Elasticsearch::NotElasticsearchError
44+
expect { client.cluster.health }.to raise_error Elasticsearch::UnsupportedProductError, message
4545
end
4646

4747
def valid_requests_and_expectations
@@ -240,7 +240,7 @@ def valid_requests_and_expectations
240240
verify_request_stub
241241
count_request_stub
242242

243-
error_requests_and_expectations
243+
error_requests_and_expectations(Elasticsearch::NOT_SUPPORTED_ELASTICSEARCH_WARNING)
244244
end
245245
end
246246

@@ -423,7 +423,7 @@ def valid_requests_and_expectations
423423
verify_request_stub
424424
count_request_stub
425425

426-
error_requests_and_expectations
426+
error_requests_and_expectations(Elasticsearch::NOT_SUPPORTED_ELASTICSEARCH_WARNING)
427427
end
428428
end
429429
end

0 commit comments

Comments
 (0)