Class: Ridley::Middleware::ChefResponse

Inherits:
Faraday::Response::Middleware
  • Object
show all
Includes:
Logging
Defined in:
lib/ridley/middleware/chef_response.rb

Overview

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

logger, #logger, set_logger

Class Method Details

.success?(env) ⇒ Boolean

Determines if a response from the Chef server was successful

Parameters:

  • env (Hash)

    a faraday request env

Returns:

  • (Boolean)

12
13
14
# File 'lib/ridley/middleware/chef_response.rb', line 12

def success?(env)
  (200..210).to_a.index(env[:status].to_i) ? true : false
end

Instance Method Details

#on_complete(env) ⇒ Object


19
20
21
22
23
24
25
26
27
# File 'lib/ridley/middleware/chef_response.rb', line 19

def on_complete(env)
  log.debug { "==> handling Chef response" }
  log.debug { "request env: #{env}" }
  
  unless self.class.success?(env)
    log.debug { "** error encounted in Chef response" }
    raise Errors::HTTPError.fabricate(env)
  end
end