I’m using Rails 4.2.7. Currently Im’ requesting web pages through a SOCKS proxy like so
begin
...
res1 = Net::HTTP.SOCKSProxy('127.0.0.1', 50001).start(uri.host, uri.port) do |http|
puts "launching #{uri}"
resp = http.get(uri)
status = resp.code
content = resp.body
content_type = resp['content-type']
content_encoding = resp['content-encoding']
end
...
rescue OpenURI::HTTPError => ex
...
rescue SocketError, Net::OpenTimeout, Zlib::BufError => e
...
end
and occasionally I will get the following error ..
Error during processing: Failed to open TCP connection to otherwebsite.com:80 (general SOCKS server failure)
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:878:in `connect'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:852:in `start'
/Users/mikeb/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:584:in `start'
/Users/mikeb/Documents/workspace/runtrax/app/helpers/webpage_helper.rb:96:in `get_content'
/Users/mikeb/Documents/workspace/runtrax/app/helpers/webpage_helper.rb:32:in `get_url'
/Users/mikeb/Documents/workspace/runtrax/app/services/onlinerr_race_finder_service.rb:42:in `get_race_list'
/Users/mikeb/Documents/workspace/runtrax/app/services/abstract_race_finder_service.rb:26:in `process_data'
/Users/mikeb/Documents/workspace/runtrax/app/services/run_crawlers_service.rb:18:in `block in run_all_crawlers'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each'
How do I catch this error and retry my request?
Edit: How is my question different than what was asked? The duplicate is referring to a buffer error, this quesiton deals with a socket error.