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::ReadTimeout,
  Net::OpenTimeout,
  Net::ProtocolError,
  Errno::ECONNREFUSED,
  Errno::EHOSTDOWN,
  Errno::ECONNRESET,
  OpenSSL::SSL::SSLError,
  EOFError,
].freeze
VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.check_response!(res) ⇒ Object

Raises:



27
28
29
30
# File 'lib/http/exceptions.rb', line 27

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

.wrap_and_checkObject



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

def self.wrap_and_check
  wrap_exception do
    check_response! yield
  end
end

.wrap_exceptionObject



19
20
21
22
23
24
25
# File 'lib/http/exceptions.rb', line 19

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