Created
December 10, 2017 20:14
-
-
Save bparanj/3fe396bfb10a7eb779ee2accc7db6f89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
# Handling Network Connection Failure | |
begin | |
http = Net::HTTP.new('localhost', '3000') | |
http.open_timeout = 3 | |
http.read_timeout = 3 | |
http.get('/') | |
rescue Errno::ECONNREFUSED => e | |
puts 'The server is down.' | |
puts e.message | |
# Retry a few times and fail with connection refused error message | |
rescue Timeout::Error => e | |
puts 'Timeout error occurred.' | |
puts e.message | |
# Retry a few times and fail with timeout error message | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handing the network is down issue.