Created
August 4, 2011 18:31
-
-
Save alkema/1125860 to your computer and use it in GitHub Desktop.
More verbose "connection refused" errors when doing REST with RestClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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