Exception: DeepL::Exceptions::ConnectionError
- Defined in:
- lib/deepl/exceptions/connection_error.rb
Overview
Raised by DeepL::Client and DeepL::AdminClient for a network failure without a complete HTTP
response from the API (DNS, connection, TLS, proxy, timeout or a body cut off mid-read), after
the retries are used up. Transient failures (DNS, connection, timeout, cut-off body) are
retried and have should_retry? true; TLS failures, proxy failures and malformed responses
are raised at once and have should_retry? false. Requests that create a resource retry only
transient failures while connecting (DNS, refused connection, unreachable host or network,
connection timeout, a reset during the TLS or proxy handshake), before the request is sent; of
their other failures, only a cut-off body has should_retry? true. The original exception is
available as cause.
Instance Attribute Summary
Attributes inherited from Error
Class Method Summary collapse
-
.from_network_error(error, should_retry: true) ⇒ Object
Raised from a
rescueblock, so the original exception becomescause. - .transient?(error) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(message = nil, should_retry: true) ⇒ ConnectionError
constructor
A new instance of ConnectionError.
- #should_retry? ⇒ Boolean
Constructor Details
#initialize(message = nil, should_retry: true) ⇒ ConnectionError
Returns a new instance of ConnectionError.
30 31 32 33 |
# File 'lib/deepl/exceptions/connection_error.rb', line 30 def initialize( = nil, should_retry: true) super() @should_retry = should_retry end |
Class Method Details
.from_network_error(error, should_retry: true) ⇒ Object
Raised from a rescue block, so the original exception becomes cause.
should_retry: false marks a failure after which the request may have been processed.
21 22 23 24 |
# File 'lib/deepl/exceptions/connection_error.rb', line 21 def self.from_network_error(error, should_retry: true) new("Connection to the DeepL API failed: #{error.}", should_retry: should_retry && transient?(error)) end |
.transient?(error) ⇒ Boolean
26 27 28 |
# File 'lib/deepl/exceptions/connection_error.rb', line 26 def self.transient?(error) Requests::Base::RETRYABLE_NETWORK_ERRORS.any? { |type| error.is_a?(type) } end |
Instance Method Details
#should_retry? ⇒ Boolean
35 36 37 |
# File 'lib/deepl/exceptions/connection_error.rb', line 35 def should_retry? @should_retry end |