Topic: How to test / prevent errors for TimeOut

hey.
i have this line of code in a Def

xml_data = Net::HTTP.get_response(URI.parse(feed_url)).body

If this times out it causes a fatal error.


/home/ssg/.gem/ruby/1.8/gems/rails-2.3.8/lib/commands/runner.rb:48: /usr/lib/ruby/1.8/timeout.rb:64:in `rbuf_fill': execution expired (Timeout::Error)

How can i Catch this so if it does time out, its not a fatal error?

THanks!

Re: How to test / prevent errors for TimeOut

begin
  xml_data = Net::HTTP.get_response(URI.parse(feed_url)).body
rescue Errno::ETIMEDOUT => exc
     puts ´ERROR: #{exc.message}´
end

Last edited by robzdc (2013-04-08 15:04:04)