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
On Fri, Nov 13, 2009 at 9:40 AM, jhaagmans
<jaap.haagmans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> 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!
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 :) On 13 nov, 20:23, Darian Shimy <dsh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.comhttp://twitter.com/dshimy > > On Fri, Nov 13, 2009 at 9:40 AM, jhaagmans <jaap.haagm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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! > >