vendor/plugins/mocha/vendor/meta_project-0.4.15/lib/meta_project/core_ext/open_uri.rb
# Wrapper around Kernel.open from open-uri
# that can retry and report better errors
Wrapper around Kernel.open from open-uri
that can retry and report better errors
Wrapper around Kernel . open from open - uri that can retry and report better errors
def better_open(url, headers=nil, retries=2, &block)
  begin
    headers.nil? ? Kernel.open(url, &block) : Kernel.open(url, headers, &block)
  rescue Errno::ECONNREFUSED, EOFError => e
    if(retries > 0)
      STDERR.puts "Connection refused to #{url} - retrying in 1 sec."
      sleep 1
      better_open(url, headers, retries-1, &block)
    else
      e.message << " (URL:#{url})"
      raise e
    end
  rescue OpenURI::HTTPError => e
    e.message << " (URL:#{url})"
    raise e
  end
end
def better_open ( url , headers = nil , retries = 2 , & block ) begin headers . nil? ? Kernel . open ( url , & block ) : Kernel . open ( url , headers , & block ) rescue Errno :: ECONNREFUSED , EOFError => e if ( retries > 0 ) STDERR . puts "Connection refused to #{url} - retrying in 1 sec." sleep 1 better_open ( url , headers , retries - 1 , & block ) else e . message << " (URL:#{url})" raise e end rescue OpenURI :: HTTPError => e e . message << " (URL:#{url})" raise e end end
Wrapper around Kernel.open from open-uri
that can retry and report better errors
Wrapper around Kernel . open from open - uri that can retry and report better errors
# open-uri's open
url
<not_specific>
headers
<not_specific>
retries
<not_specific>
block
<not_specific>