# Net::HTTP question

**URL:** <https://www.ruby-forum.com/t/net-http-question/178937>\
**Category:** Rails\
**Created:** [November 13, 2009, 8:15pm UTC](https://www.ruby-forum.com/t/net-http-question/178937 "2009-11-13T20:15:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [November 13, 2009, 8:15pm UTC](https://www.ruby-forum.com/t/net-http-question/178937/1 "2009-11-13T20:15:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [November 13, 2009, 8:27pm UTC](https://www.ruby-forum.com/t/net-http-question/178937/2 "2009-11-13T20:27:15Z")

</div>

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://www.darianshimy.com)  
[http://twitter.com/dshimy](http://twitter.com/dshimy)
