Sha256: 62ad737835feb8bebbca5993a3cb765c02c534fb9f6ce35c452f929d10be0a36

Contents?: true

Size: 723 Bytes

Versions: 7

Compression:

Stored size: 723 Bytes

Contents

module AnsibleTowerClient
  module Middleware
    class RaiseTowerError < Faraday::Response::Middleware
      CLIENT_ERROR_STATUSES = 400...600

      def on_complete(env)
        case env[:status]
        when 404
          raise Faraday::Error::ResourceNotFound, response_values(env)
        when 407
          # mimic the behavior that we get with proxy requests with HTTPS
          raise Faraday::Error::ConnectionFailed, %(407 "Proxy Authentication Required ")
        when CLIENT_ERROR_STATUSES
          raise Faraday::Error::ClientError, env.body
        end
      end

      def response_values(env)
        {:status => env.status, :headers => env.response_headers, :body => env.body}
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ansible_tower_client-0.4.1 lib/ansible_tower_client/middleware/raise_tower_error.rb
ansible_tower_client-0.4.0 lib/ansible_tower_client/middleware/raise_tower_error.rb
ansible_tower_client-0.3.3 lib/ansible_tower_client/middleware/raise_tower_error.rb
ansible_tower_client-0.3.2 lib/ansible_tower_client/middleware/raise_tower_error.rb
ansible_tower_client-0.3.1 lib/ansible_tower_client/middleware/raise_tower_error.rb
ansible_tower_client-0.3.0 lib/ansible_tower_client/middleware/raise_tower_error.rb
ansible_tower_client-0.2.0 lib/ansible_tower_client/middleware/raise_tower_error.rb