Sha256: 563aade637e5efb19575c08d8ed0677a7ffa99dba3ec86aa65baf118310f5849

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Aranha
  class AddressProcessor
    ARANHA_EXCEPTIONS = [::Aranha::Parsers::InvalidStateException].freeze
    CORE_EXCEPTIONS = [::SocketError].freeze
    ERRNO_EXCEPTIONS = [Errno::ECONNREFUSED, ::Errno::ECONNRESET].freeze
    HTTPCLIENT_EXCEPTIONS = [
      ::HTTPClient::BadResponseError,
      ::HTTPClient::ConnectTimeoutError,
      ::HTTPClient::ReceiveTimeoutError
    ].freeze
    NET_EXCEPTIONS = [::Net::HTTPFatalError, ::Net::HTTPServerException, ::Net::OpenTimeout].freeze

    NETWORK_EXCEPTIONS = ARANHA_EXCEPTIONS + CORE_EXCEPTIONS + ERRNO_EXCEPTIONS +
                         HTTPCLIENT_EXCEPTIONS + NET_EXCEPTIONS

    class << self
      def rescuable_error?(error)
        return true if NETWORK_EXCEPTIONS.any? { |klass| error.is_a?(klass) }

        error.cause.present? ? network_error?(error.cause) : false
      end
    end

    enable_simple_cache
    common_constructor :address

    def successful?
      error.blank?
    end

    def rescuable_error?
      self.class.rescuable_error?(error)
    end

    private

    def error_uncached
      address.process
      nil
    rescue ::StandardError => e
      e
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aranha-0.17.1 lib/aranha/address_processor.rb
aranha-0.17.0 lib/aranha/address_processor.rb
aranha-0.16.1 lib/aranha/address_processor.rb
aranha-0.16.0 lib/aranha/address_processor.rb