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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77ec30d6589d64d4748196987a812cf8e7fe51ddc740493a75386b7d05a5fa61
4
- data.tar.gz: 0dfe079e1fe86aa2bb93bf9dda4db422a97bc14e6af9fb1bbedbf0cb68ea721e
3
+ metadata.gz: 89a3ded7c81fa35f89b068b462b18afd39598b96028014f9a3f67d116185fb01
4
+ data.tar.gz: ed95009629d9b59d69681eb88bcc97829644613a22b307a49a7a79c24906bc25
5
5
  SHA512:
6
- metadata.gz: 1e35fc7b442007cf84f1c530e01aecaaf49c3e0fb2f00f6069eecb714479877e1d88c79332491ce25746100aaafa5ee2d3c98bb30ab419652dc7fe5617ead17a
7
- data.tar.gz: 5c92d32d80af5fa318b6fa82f87baf6ad39a019d53c5b913752d7851f2f41407c6a5bcc98c3292f39993f3eea4b31e3ff3def9941c959aa2ede7a1668b69e645
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.0'` in your `Gemfile` and run `bundle install`.
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 = if response.is_a?(Array)
8
- response.flat_map { |r| r['errors'] }
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
@@ -1,5 +1,5 @@
1
1
  module Elastic
2
2
  module AppSearch
3
- VERSION = '7.3.0'
3
+ VERSION = '7.3.1'
4
4
  end
5
5
  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.0
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-08-26 00:00:00.000000000 Z
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