Exception: DeepL::Exceptions::ConnectionError

Inherits:
Error
  • Object
show all
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

#http_status_code

Class Method Summary collapse

Instance Method Summary collapse

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(message = nil, should_retry: true)
  super(message)
  @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.message}",
      should_retry: should_retry && transient?(error))
end

.transient?(error) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/deepl/exceptions/connection_error.rb', line 35

def should_retry?
  @should_retry
end