Module: Http::Exceptions

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

Defined Under Namespace

Classes: 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.0.4"

Class Method Summary collapse

Class Method Details

.check_response!(res) ⇒ Object

Raises:



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

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

.wrap_and_checkObject



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

def self.wrap_and_check
  wrap_exception do
    check_response! yield
  end
end

.wrap_exceptionObject



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

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