Net::HTTP when server doesn' exists?


#1

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