Skip to content

Instantly share code, notes, and snippets.

@alkema
Created August 4, 2011 18:31
Show Gist options
  • Save alkema/1125860 to your computer and use it in GitHub Desktop.
Save alkema/1125860 to your computer and use it in GitHub Desktop.
More verbose "connection refused" errors when doing REST with RestClient
context "REST requests" do
use_vcr_cassette "connection_refused_error", :record => :all
message = "Connection refused - when attempting request: POST http://localhost:80 with headers: and payload: payload"
it "should tell me what happened when it was a refused connection" do
lambda {
RestClient.post("http://localhost:80", 'payload')
}.should raise_error(Errno::ECONNREFUSED, message)
end
end
require 'rest_client'
RestClient::Request.class_eval do
def self.execute(args, & block)
begin
new(args).execute(& block)
rescue Errno::ECONNREFUSED => e
$stderr.puts e.message
$stderr.puts e.backtrace.inspect
$stderr.puts args.inspect
message = "when attempting request: #{args[:method].to_s.upcase} #{args[:url]} with headers: #{args[:headers]} and payload: #{args[:payload]}"
raise Errno::ECONNREFUSED, message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment