Handling Net :: HTTP.get Failures

Next line:

page_source = Net::HTTP.get(URI.parse("http://not-a-real-url.com")) 

When passing a URL that is correctly formatted but doesn't go anywhere (as in the example above), it dies with:

 getaddrinfo: nodename nor servname provided, or not known 

I am trying to figure out how to β€œstart / save” this condition, but I cannot find in the documentation what error, if any, the get method throws.

+7
ruby-on-rails error-handling
source share
1 answer

Does it help?

 begin page_source = Net::HTTP.get(URI.parse("http://not-a-real-url.com")) rescue SocketError => e puts e.message end 
+9
source

All Articles