Module: ActiveUtils::NetworkConnectionRetries
- Included in:
- Connection
- Defined in:
- lib/active_utils/network_connection_retries.rb
Constant Summary collapse
- DEFAULT_RETRIES =
3
- DEFAULT_CONNECTION_ERRORS =
{ EOFError => "The remote server dropped the connection", Errno::ECONNRESET => "The remote server reset the connection", 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" }
- DEFAULT_RETRY_ERRORS =
{ Errno::ECONNREFUSED => "The remote server refused the connection" }
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
17 18 19 |
# File 'lib/active_utils/network_connection_retries.rb', line 17 def self.included(base) base.send(:attr_accessor, :retry_safe) end |
Instance Method Details
#retry_exceptions(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_utils/network_connection_retries.rb', line 21 def retry_exceptions(={}) connection_errors = DEFAULT_CONNECTION_ERRORS.merge([:connection_exceptions] || {}) retry_errors = DEFAULT_RETRY_ERRORS.merge([:retriable_exceptions] || {}) retry_network_exceptions() do begin yield rescue *retry_errors.keys => e raise ActiveUtils::RetriableConnectionError, (retry_errors, e.class) rescue OpenSSL::X509::CertificateError => e NetworkConnectionRetries.log([:logger], :error, e., [:tag]) raise ActiveUtils::ClientCertificateError, "The remote server did not accept the provided SSL certificate" rescue Zlib::BufError => e raise ActiveUtils::InvalidResponseError, "The remote server replied with an invalid response" rescue *connection_errors.keys => e raise ActiveUtils::ConnectionError, (connection_errors, e.class) end end end |