Net::HTTP question

Hi,

I’m doing this:

response = Net::HTTP.start(host).request_head(’/’)

To check a domain for its response. Now some of the domains checked
will not exist and thus produce the following error:

SocketError: getaddrinfo: Name or service not known

But I don’t want my application to fail when this happens, I just want
the response to be nil. How can this be done?

Thank you!

Did you try a rescue block:

begin
response = Net::HTTP.start(host).request_head(‘/’)
rescue SocketError => e

Handle error

end


Darian Shimy

http://www.darianshimy.com
http://twitter.com/dshimy