elastic-app-search 7.3.0 → 7.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/elastic/app-search/exceptions.rb +9 -6
- data/lib/elastic/app-search/version.rb +1 -1
- data/spec/exceptions_spec.rb +69 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89a3ded7c81fa35f89b068b462b18afd39598b96028014f9a3f67d116185fb01
|
4
|
+
data.tar.gz: ed95009629d9b59d69681eb88bcc97829644613a22b307a49a7a79c24906bc25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e23120e2e4c6185a769a505a53aaa9640be158dbf2bfd01d957f6acf4fc167c471e1403d8e45c396933bb4e66af892a200ddc91b2f233db77a670c6fffaafd
|
7
|
+
data.tar.gz: 174322921e02fcdba0b86075ebd931a4a10273d51ce26593cf1bdecccf1603a01b295fd11652d1e06db45abbe200512bd614bbc6279768d5b4570309c95b40e8
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ To install the gem, execute:
|
|
25
25
|
gem install elastic-app-search
|
26
26
|
```
|
27
27
|
|
28
|
-
Or place `gem 'elastic-app-search', '~> 7.3.
|
28
|
+
Or place `gem 'elastic-app-search', '~> 7.3.1'` in your `Gemfile` and run `bundle install`.
|
29
29
|
|
30
30
|
## Versioning
|
31
31
|
|
@@ -3,13 +3,16 @@ module Elastic
|
|
3
3
|
class ClientException < StandardError
|
4
4
|
attr_reader :errors
|
5
5
|
|
6
|
+
def extract_messages(response)
|
7
|
+
errors_value = response['errors']
|
8
|
+
return errors_value if errors_value && errors_value.is_a?(Array)
|
9
|
+
return [errors_value] if errors_value && !errors_value.is_a?(Array)
|
10
|
+
[response]
|
11
|
+
end
|
12
|
+
|
6
13
|
def initialize(response)
|
7
|
-
@errors =
|
8
|
-
|
9
|
-
else
|
10
|
-
response['errors'] || [response]
|
11
|
-
end
|
12
|
-
message = (errors.count == 1) ? "Error: #{errors.first}" : "Errors: #{errors.inspect}"
|
14
|
+
@errors = response.is_a?(Array) ? response.flat_map { |r| extract_messages(r) } : extract_messages(response)
|
15
|
+
message = (errors.size == 1) ? "Error: #{errors.first}" : "Errors: #{errors.inspect}"
|
13
16
|
super(message)
|
14
17
|
end
|
15
18
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
describe Elastic::AppSearch::ClientException do
|
2
|
+
describe "when parsing a response body" do
|
3
|
+
describe "and there is an 'errors' property on the response" do
|
4
|
+
it 'will parse a single error message' do
|
5
|
+
expect(Elastic::AppSearch::ClientException.new(
|
6
|
+
{ "errors" => [ "Unauthorized action." ] }
|
7
|
+
).message).to eq("Error: Unauthorized action.")
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'will parse multiple error messages' do
|
11
|
+
expect(Elastic::AppSearch::ClientException.new(
|
12
|
+
{ "errors" => [ "Unauthorized action.", "Service unavailable" ] }
|
13
|
+
).message).to eq("Errors: [\"Unauthorized action.\", \"Service unavailable\"]")
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'will parse when there is a string instead of an array in errors' do
|
17
|
+
expect(Elastic::AppSearch::ClientException.new(
|
18
|
+
{ "errors" => "Routing Error. The path you have requested is invalid." }
|
19
|
+
).message).to eq("Error: Routing Error. The path you have requested is invalid.")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when there is an array of responses" do
|
24
|
+
it 'will parse a single error message' do
|
25
|
+
expect(Elastic::AppSearch::ClientException.new(
|
26
|
+
[
|
27
|
+
{ "errors" => [ "Unauthorized action." ] },
|
28
|
+
{ "errors" => [ "Service unavailable" ] }
|
29
|
+
]
|
30
|
+
).message).to eq("Errors: [\"Unauthorized action.\", \"Service unavailable\"]")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'will parse multiple error messages' do
|
34
|
+
expect(Elastic::AppSearch::ClientException.new(
|
35
|
+
[
|
36
|
+
{ "errors" => [ "Unauthorized action.", "Service unavailable" ] },
|
37
|
+
{ "errors" => [ "Another error" ] }
|
38
|
+
]
|
39
|
+
).message).to eq("Errors: [\"Unauthorized action.\", \"Service unavailable\", \"Another error\"]")
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'will parse when there is a string instead of an array in errors' do
|
43
|
+
expect(Elastic::AppSearch::ClientException.new(
|
44
|
+
[
|
45
|
+
{ "errors" => [ "Unauthorized action.", "Service unavailable" ] },
|
46
|
+
{ "errors" => [ "Another error" ] },
|
47
|
+
{ "errors" => "Routing Error. The path you have requested is invalid." }
|
48
|
+
]
|
49
|
+
).message).to eq("Errors: [\"Unauthorized action.\", \"Service unavailable\", \"Another error\", \"Routing Error. The path you have requested is invalid.\"]")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "and there is a single 'error'" do
|
54
|
+
it 'will just return the entire response body' do
|
55
|
+
expect(Elastic::AppSearch::ClientException.new(
|
56
|
+
{ "error" => "Unauthorized action." }
|
57
|
+
).message).to eq("Error: {\"error\"=>\"Unauthorized action.\"}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "and there is a just a string" do
|
62
|
+
it 'will just return the entire response body' do
|
63
|
+
expect(Elastic::AppSearch::ClientException.new(
|
64
|
+
"Unauthorized action."
|
65
|
+
).message).to eq("Error: Unauthorized action.")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-app-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.3.
|
4
|
+
version: 7.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Quin Hoxie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- script/console
|
120
120
|
- spec/client_spec.rb
|
121
121
|
- spec/config_helper.rb
|
122
|
+
- spec/exceptions_spec.rb
|
122
123
|
- spec/spec_helper.rb
|
123
124
|
homepage: https://github.com/elastic/app-search-ruby
|
124
125
|
licenses:
|
@@ -147,4 +148,5 @@ summary: Official gem for accessing the Elastic App Search API
|
|
147
148
|
test_files:
|
148
149
|
- spec/client_spec.rb
|
149
150
|
- spec/config_helper.rb
|
151
|
+
- spec/exceptions_spec.rb
|
150
152
|
- spec/spec_helper.rb
|