I want to keep trying to get response until its code is 200 or unknown yet. In first case it should be stored in response
variable. In another case I should raise any kind of exception.
response = nil
1.times do
response = begin
http.request request
rescue Net::ReadTimeout
puts "Net::ReadTimeout"
retry
end
case response.code
when "503"
puts "servers are busy at #{Time.now}?"
sleep 5
redo
when "200"
"ok"
else
fail "#{response.code} at '#{request.path}'"
end
end
The 1.times
thing is taken from SO.