From 4ae3dcbb5d3236b76158364d23e017ca9a61d2ed Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 11 Apr 2019 10:09:40 -0400 Subject: [PATCH] Add Errno::EHOSTUNREACH to connection errors This adds Errno::EHOSTUNREACH to the list of default connection errors. This exception is occasionally raised from the Net::HTTP library and should be handled the same way as other connection errors. --- lib/active_utils/network_connection_retries.rb | 1 + test/unit/network_connection_retries_test.rb | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/active_utils/network_connection_retries.rb b/lib/active_utils/network_connection_retries.rb index f2d3541..6ee2edf 100644 --- a/lib/active_utils/network_connection_retries.rb +++ b/lib/active_utils/network_connection_retries.rb @@ -7,6 +7,7 @@ module NetworkConnectionRetries Timeout::Error => "The connection to the remote server timed out", Errno::ETIMEDOUT => "The connection to the remote server timed out", SocketError => "The connection to the remote server could not be established", + Errno::EHOSTUNREACH => "The connection to the remote server could not be established", OpenSSL::SSL::SSLError => "The SSL connection to the remote server could not be established" } diff --git a/test/unit/network_connection_retries_test.rb b/test/unit/network_connection_retries_test.rb index 80ffed5..6eaa2da 100644 --- a/test/unit/network_connection_retries_test.rb +++ b/test/unit/network_connection_retries_test.rb @@ -48,13 +48,17 @@ def test_timeout_errors_raise_correctly end end - def test_socket_error_raises_correctly - raised = assert_raises(ActiveUtils::ConnectionError) do - retry_exceptions do - raise SocketError + def test_connection_errors_raise_correctly + exceptions = [SocketError, Errno::EHOSTUNREACH] + + exceptions.each do |exception| + raised = assert_raises(ActiveUtils::ConnectionError) do + retry_exceptions do + raise exception + end end + assert_equal "The connection to the remote server could not be established", raised.message end - assert_equal "The connection to the remote server could not be established", raised.message end def test_ssl_errors_raise_correctly