The callback block is executed only when receiving some response from the server. In this case, the name resolving is failed so RestClient.get
just throws an exception without entering the block. Thus just wrap your code within a begin...end
construct.
begin
RestClient.get('http://thisurldoesnotexist/resource') { |response, request, result, &block|
case response.code
when 200
p "It worked !"
response
else
response.return!(request, result, &block)
end
}
rescue SocketError => e
# Handle your error here
end