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

Yes, I did last night (I hadn't noticed your response). I will have to
approach the situation a little bit differently, but it might just
work. Thank you :slight_smile: