Hey list-
I have the following code that seems to work fine:
require 'net/http'
def fetch(page, section='display', limit=5)
data = ''
begin
data = Net::HTTP.get_response("192.168.0.2", "/#{page}")
rescue Exception => e
limit -= 1
limit > 0 ? retry : raise
end
data.body.gsub!(/\/temporaryimages/, "http://192.168.0.2/temporaryimages")
data.body.gsub!(/\/wrappers\/(\d+)\.news/i, "/page/#{section}/\1")
end
I am using it to fetch some templated web pages from an in house server that almost never errors out. So my code works fine. But I am wondering if this code will do what I think it should do upon failure. Before I added the begin/rescue/end block, the server would occasionally error out with a connection reset by peer error. So my question is will this syntax work to retry fetching the page 5 times before it gives up. Will the rescue Exception => e part catch pretty much any type of error?
Thanks in advance for anyone explaining this to me or offering a more robust solution.
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
509-577-7732
ezra@yakima-herald.com