Timeout::Error
It really sucks that sometimes webservice request just hangs. What’s worse, some methods for some strange reasons returns Timeout::Error. My way of handling such problem is force a timeout. This can be done simply by wrapping the offending method or block within Timeout::timeout method. Here’s an example of what I mean:
require 'timeout'
...
begin
Timeout::timeout(2) do
# request to web for certain value
end
rescue
# put your rescue code here...
end
...
By passing 2, I’m telling the method to wait 2 seconds before raising timeout exception.