My question is related to http://stackoverflow.com/questions/2370140/how-to-rescue-timeout-issues-ruby-rails.
Here's the common way to rescue from a timeout:
# Post using Net::HTTP
rescue Timeout::Error => e
# Do something
Here's the solution (after Ben's fix):
require "net/http" http = Net::HTTP.new("example.com") http.open_timeout = 2 http.read_timeout = 3 begin http.start begin http.request_get("/whatever?") do |res| res.read_body end rescue Timeout::Error puts "Timeout due to reading" end rescue Timeout::Error puts "Timeout due to connecting" end