class AnsibleTowerClient::Middleware::RaiseTowerError

Constants

CLIENT_ERROR_STATUSES

Public Instance Methods

on_complete(env) click to toggle source
# File lib/ansible_tower_client/middleware/raise_tower_error.rb, line 7
def on_complete(env)
  return unless CLIENT_ERROR_STATUSES.include?(env[:status])
  logger.debug { "#{self.class.name} Raw Response:\n#{env.pretty_inspect}" }
  logger.error("#{self.class.name} Response Body:\n#{log_from_response(env)}")

  case env[:status]
  when 402
    raise AnsibleTowerClient::UnlicensedFeatureError
  when 404
    raise AnsibleTowerClient::ResourceNotFoundError, response_values(env)
  when 407
    # mimic the behavior that we get with proxy requests with HTTPS
    raise AnsibleTowerClient::ConnectionError, %(407 "Proxy Authentication Required ")
  else
    raise AnsibleTowerClient::ClientError, env.body
  end
end
response_values(env) click to toggle source
# File lib/ansible_tower_client/middleware/raise_tower_error.rb, line 25
def response_values(env)
  {
    :headers => env.response_headers,
    :status  => env.status,
    :body    => env.body,
    :url     => env.url,
  }
end