Module: Eson::StatusHandler

Defined in:
lib/eson/modules/status_handler.rb

Overview

A plugin to handle status codes.

Instance Method Summary collapse

Instance Method Details

#call(*args) ⇒ Object



4
5
6
# File 'lib/eson/modules/status_handler.rb', line 4

def call(*args)
  handle(super)
end

#handle(response) ⇒ Object

Handle the response status.

Raises:

  • (Eson::IndexNotFoundError)

    if the index is missing

  • (Eson::NotFoundError)

    if the document is missing

  • (Eson::Error)

    otherwise



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/eson/modules/status_handler.rb', line 13

def handle(response)
  case response.status
  when 404
    if /IndexMissingException/.match(response.body)
      raise Eson::IndexNotFoundError.new(response.body, response)
    else
      raise Eson::NotFoundError.new(response, response)
    end
  else
    if response.status >= 400
      raise Eson::Error.new(response[:error], response)
    else
      response
    end
  end
end