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

VERSION =
'0.1.6'.freeze

Class Method Summary collapse

Class Method Details

.check_response!(res) ⇒ Object

Raises:



15
16
17
18
# File 'lib/http/exceptions.rb', line 15

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

.configurationObject

The configuration object.

See Also:



40
41
42
# File 'lib/http/exceptions.rb', line 40

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:



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

def self.configure
  yield(configuration)
  self
end

.wrap_and_checkObject



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

def self.wrap_and_check
  wrap_exception do
    check_response! yield
  end
end

.wrap_exceptionObject



7
8
9
10
11
12
13
# File 'lib/http/exceptions.rb', line 7

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