Class: Swiftype::Connection::ApiResponseMiddleware

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/swiftype/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ApiResponseMiddleware

Returns a new instance of ApiResponseMiddleware.



41
42
43
44
# File 'lib/swiftype/connection.rb', line 41

def initialize(app)
  super
  @parser = nil
end

Instance Method Details

#on_complete(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/swiftype/connection.rb', line 26

def on_complete(env)
  case env[:status]
  when 200, 201, 204
    nil
  when 401
    raise InvalidCredentials
  when 404
    raise NonExistentRecord
  when 409
    raise RecordAlreadyExists
  else
    raise UnexpectedHTTPException, env[:body]
  end
end