Sha256: 492c0c98a84094760202d30152b0bf1343a2f20b4605d00e675604a57849a412

Contents?: true

Size: 820 Bytes

Versions: 11

Compression:

Stored size: 820 Bytes

Contents

require 'faraday'

module PuppetForge
  module Connection
    # Wrap Faraday connection failures to include the host and optional proxy
    # in use for the failed connection.
    class ConnectionFailure < Faraday::Middleware
      def call(env)
        @app.call(env)
      rescue Faraday::ConnectionFailed => e
        baseurl = env[:url].dup
        baseurl.path = ''
        errmsg = "Unable to connect to #{baseurl.to_s}"
        if proxy = env[:request][:proxy]
          errmsg << " (using proxy #{proxy.uri.to_s})"
        end
        errmsg << ": #{e.message}"
        m = Faraday::ConnectionFailed.new(errmsg)
        m.set_backtrace(e.backtrace)
        raise m
      end
    end
  end
end

Faraday::Middleware.register_middleware(:connection_failure => lambda { PuppetForge::Connection::ConnectionFailure })

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
puppet_forge-2.2.1 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.2.0 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.1.5 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.1.4 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.1.3 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.1.2 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.1.1 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.1.0 lib/puppet_forge/connection/connection_failure.rb
puppet_forge-2.0.0 lib/puppet_forge/connection/connection_failure.rb
r10k-2.0.3 lib/shared/puppet_forge/connection/connection_failure.rb
r10k-2.0.2 lib/shared/puppet_forge/connection/connection_failure.rb