Skip to content

Commit

Permalink
Catch and raise EHOSTUNREACH and EADDRNOTAVAI syscall errors as Activ…
Browse files Browse the repository at this point in the history
…eUtils::ConnectionError
  • Loading branch information
maximus1108 committed Feb 4, 2025
1 parent c3f620e commit cee4e2a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ActiveUtils changelog

### Version 3.5.0 (February 04, 2025)
- Catch and raise `EHOSTUNREACH` and `EADDRNOTAVAIL` syscall errors as `ActiveUtils::ConnectionError`

### Version 3.4.2 (January 15, 2025)
- Remove numeric as a required param for `ActiveUtils::Country`

Expand Down
4 changes: 3 additions & 1 deletion lib/active_utils/network_connection_retries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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",
OpenSSL::SSL::SSLError => "The SSL connection to the remote server could not be established"
OpenSSL::SSL::SSLError => "The SSL connection to the remote server could not be established",
Errno::EHOSTUNREACH => "The remote server could not be reached",
Errno::EADDRNOTAVAIL => "The remote server address is not available"
}

DEFAULT_RETRY_ERRORS = {
Expand Down
2 changes: 1 addition & 1 deletion lib/active_utils/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveUtils
VERSION = "3.4.2"
VERSION = "3.5.0"
end
18 changes: 18 additions & 0 deletions test/unit/network_connection_retries_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ def test_econnreset_raises_correctly
assert_equal "The remote server reset the connection", raised.message
end

def test_ehostunreach_raises_correctly
raised = assert_raises(ActiveUtils::ConnectionError) do
retry_exceptions do
raise Errno::EHOSTUNREACH
end
end
assert_equal "The remote server could not be reached", raised.message
end

def test_eaddrnotavail_raises_correctly
raised = assert_raises(ActiveUtils::ConnectionError) do
retry_exceptions do
raise Errno::EADDRNOTAVAIL
end
end
assert_equal "The remote server address is not available", raised.message
end

def test_timeout_errors_raise_correctly
exceptions = [Timeout::Error, Errno::ETIMEDOUT]
if RUBY_VERSION >= '2.0.0'
Expand Down

0 comments on commit cee4e2a

Please sign in to comment.