Module: Http::Exceptions

Defined in:
lib/http/exceptions.rb,
lib/http/exceptions/version.rb,
lib/http/exceptions/configuration.rb,
lib/http/exceptions/http_exception.rb

Defined Under Namespace

Classes: Configuration, HttpException

Constant Summary collapse

EXCEPTIONS =
[
  SocketError,
  Errno::ETIMEDOUT,
  (Net.const_defined?(:ReadTimeout) ? Net::ReadTimeout : EOFError),
  (Net.const_defined?(:OpenTimeout) ? Net::OpenTimeout : EOFError),
  Net::ProtocolError,
  Errno::ECONNREFUSED,
  Errno::EHOSTDOWN,
  Errno::ECONNRESET,
  Errno::ENETUNREACH,
  Errno::EHOSTUNREACH,
  Errno::ECONNABORTED,
  OpenSSL::SSL::SSLError,
  EOFError,
].freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.check_response!(res) ⇒ Object

Raises:



31
32
33
34
# File 'lib/http/exceptions.rb', line 31

def self.check_response!(res)
  raise HttpException.new(response: res) unless (200...300).include?(res.code)
  res
end

.configurationObject

The configuration object.

See Also:



56
57
58
# File 'lib/http/exceptions.rb', line 56

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

Http::Exceptions.configure do |config|
  config.exceptions_to_convert = [Net::ProtocolError]
  config.exceptions_to_convert << EOFError
end

Yields:



49
50
51
52
# File 'lib/http/exceptions.rb', line 49

def self.configure
  yield(configuration)
  self
end

.wrap_and_checkObject



36
37
38
39
40
# File 'lib/http/exceptions.rb', line 36

def self.wrap_and_check
  wrap_exception do
    check_response! yield
  end
end

.wrap_exceptionObject



23
24
25
26
27
28
29
# File 'lib/http/exceptions.rb', line 23

def self.wrap_exception
  begin
    yield
  rescue *configuration.exceptions_to_convert => e
    raise HttpException.new original_exception: e
  end
end