# Net::HTTP when server doesn' exists?

**URL:** <https://www.ruby-forum.com/t/net-http-when-server-doesn-exists/85278>\
**Category:** Ruby\
**Created:** [March 22, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/net-http-when-server-doesn-exists/85278 "2006-03-22T14:28:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 22, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/net-http-when-server-doesn-exists/85278/1 "2006-03-22T14:28:56Z")

</div>

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
