Exception: Elastic::AppSearch::ClientException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/elastic/app-search/exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ClientException

Returns a new instance of ClientException.



13
14
15
16
17
# File 'lib/elastic/app-search/exceptions.rb', line 13

def initialize(response)
  @errors = response.is_a?(Array) ? response.flat_map { |r| extract_messages(r) } : extract_messages(response)
  message = (errors.size == 1) ? "Error: #{errors.first}" : "Errors: #{errors.inspect}"
  super(message)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/elastic/app-search/exceptions.rb', line 4

def errors
  @errors
end

Instance Method Details

#extract_messages(response) ⇒ Object



6
7
8
9
10
11
# File 'lib/elastic/app-search/exceptions.rb', line 6

def extract_messages(response)
  errors_value = response['errors']
  return errors_value if errors_value && errors_value.is_a?(Array)
  return [errors_value] if errors_value && !errors_value.is_a?(Array)
  [response]
end