Forum: Ruby Net::HTTP when server doesn' exists ???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-03-22 15:28
(Received via mailing list)
i did like to classify some urls :

server exists, document exists

i'm able to discriminated when server exists and document doesn't.

however when the server doesn't exists i get an error message :
SocketError: getaddrinfo: No address associated with nodename
method initialize
in http.rb at line 562
method connect
in http.rb at line 562
method timeout
in timeout.rb at line 48
method timeout
in timeout.rb at line 76
method connect
in http.rb at line 562
method do_start
in http.rb at line 555
method start
in http.rb at line 544
method get_response
in http.rb at line 379
method fetch
in verifyUrls.rb at line 11
at top level
in verifyUrls.rb at line 26


then the prog stops after this error.

i'd like better having a usable message saying something like "server
doesn't exists" but don't stop the prog.

simply, for the time being i've used the code given in RDoc :
def fetch(uri_str, limit = 10)
  # You should choose better exception.
  raise ArgumentError, 'HTTP redirect too deep' if limit == 0
  response = Net::HTTP.get_response(URI.parse(uri_str))
  case response
  when Net::HTTPSuccess     then response
  when Net::HTTPRedirection then fetch(response['location'], limit - 1)
  else
    response.error!
  end
end
This topic is locked and can not be replied to.