http-exceptions 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +17 -3
- data/lib/http/exceptions/configuration.rb +28 -0
- data/lib/http/exceptions/version.rb +1 -1
- data/lib/http/exceptions.rb +23 -1
- data/spec/http/exceptions/configuration_spec.rb +39 -0
- data/spec/http_exception_spec.rb +30 -19
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dd2e0213e9efb0ed35cb07bd193f9b86ce0f9d5
|
4
|
+
data.tar.gz: 243069506cecfd6c0ddfc1bd547147316a555f18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7deb67a6d04d8eb57c9e23a57862630f241f1958b5e3fc7378abcd9510ec36fc5f909211a4c07d5ffcef4289877b7ad966c4e7d82d6f6ae6f516737c237ea810
|
7
|
+
data.tar.gz: e106195b15e6c5edb957d7a26549b19c3f8ccabb2af0ab9388d5bae449d9f20a9c0219be35d5a57eafa3ef5a3e6d30ef22d9c3dc092ada8d0d687ddca2dee872
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
+
# Send builds to container-based infrastructure
|
2
|
+
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
3
|
+
sudo: false
|
1
4
|
language: ruby
|
5
|
+
cache:
|
6
|
+
- bundler
|
2
7
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
-
|
8
|
+
- 2.0
|
9
|
+
- 2.1.8
|
10
|
+
- 2.2.4
|
11
|
+
- 2.3.0
|
12
|
+
- ruby-head
|
6
13
|
script: bundle exec rspec spec
|
14
|
+
# ! Update bundler before running test in Travis to avoid buggy version of bundler
|
15
|
+
before_install:
|
16
|
+
- gem update bundler
|
17
|
+
matrix:
|
18
|
+
fast_finish: true
|
19
|
+
allow_failures:
|
20
|
+
- rvm: ruby-head
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Http
|
2
|
+
module Exceptions
|
3
|
+
class Configuration
|
4
|
+
DEFAULT_EXCEPTIONS_TO_CONVERT = [
|
5
|
+
SocketError,
|
6
|
+
Errno::ETIMEDOUT,
|
7
|
+
(Net.const_defined?(:ReadTimeout) ? Net::ReadTimeout : EOFError),
|
8
|
+
(Net.const_defined?(:OpenTimeout) ? Net::OpenTimeout : EOFError),
|
9
|
+
Net::ProtocolError,
|
10
|
+
Errno::ECONNREFUSED,
|
11
|
+
Errno::EHOSTDOWN,
|
12
|
+
Errno::ECONNRESET,
|
13
|
+
Errno::ENETUNREACH,
|
14
|
+
Errno::EHOSTUNREACH,
|
15
|
+
Errno::ECONNABORTED,
|
16
|
+
OpenSSL::SSL::SSLError,
|
17
|
+
EOFError,
|
18
|
+
].uniq.freeze
|
19
|
+
|
20
|
+
# Exception classes to be converted to Http::Exceptions::HttpException
|
21
|
+
attr_accessor :exceptions_to_convert
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
self.exceptions_to_convert = DEFAULT_EXCEPTIONS_TO_CONVERT
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/http/exceptions.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "http/exceptions/version"
|
2
|
+
require "http/exceptions/configuration"
|
2
3
|
require "http/exceptions/http_exception"
|
3
4
|
|
4
5
|
module Http
|
@@ -12,6 +13,9 @@ module Http
|
|
12
13
|
Errno::ECONNREFUSED,
|
13
14
|
Errno::EHOSTDOWN,
|
14
15
|
Errno::ECONNRESET,
|
16
|
+
Errno::ENETUNREACH,
|
17
|
+
Errno::EHOSTUNREACH,
|
18
|
+
Errno::ECONNABORTED,
|
15
19
|
OpenSSL::SSL::SSLError,
|
16
20
|
EOFError,
|
17
21
|
].freeze
|
@@ -19,7 +23,7 @@ module Http
|
|
19
23
|
def self.wrap_exception
|
20
24
|
begin
|
21
25
|
yield
|
22
|
-
rescue *
|
26
|
+
rescue *configuration.exceptions_to_convert => e
|
23
27
|
raise HttpException.new original_exception: e
|
24
28
|
end
|
25
29
|
end
|
@@ -34,5 +38,23 @@ module Http
|
|
34
38
|
check_response! yield
|
35
39
|
end
|
36
40
|
end
|
41
|
+
|
42
|
+
# Call this method to modify defaults in your initializers.
|
43
|
+
#
|
44
|
+
# @example
|
45
|
+
# Http::Exceptions.configure do |config|
|
46
|
+
# config.exceptions_to_convert = [Net::ProtocolError]
|
47
|
+
# config.exceptions_to_convert << EOFError
|
48
|
+
# end
|
49
|
+
def self.configure
|
50
|
+
yield(configuration)
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
# The configuration object.
|
55
|
+
# @see Http::Exceptions.configure
|
56
|
+
def self.configuration
|
57
|
+
@configuration ||= Configuration.new
|
58
|
+
end
|
37
59
|
end
|
38
60
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Http::Exceptions::Configuration do
|
4
|
+
attribute_name_and_default_value_mappings = {
|
5
|
+
exceptions_to_convert: Http::Exceptions::Configuration::DEFAULT_EXCEPTIONS_TO_CONVERT,
|
6
|
+
}.freeze
|
7
|
+
|
8
|
+
describe "default values" do
|
9
|
+
subject(:model) { described_class.new }
|
10
|
+
|
11
|
+
attribute_name_and_default_value_mappings.each do |attribute_name, default_value|
|
12
|
+
context "for attribute #{attribute_name}" do
|
13
|
+
subject { model.public_send(attribute_name) }
|
14
|
+
|
15
|
+
it {should eq(default_value)}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "configurable attributes" do
|
21
|
+
subject(:model) { described_class.new }
|
22
|
+
|
23
|
+
attribute_name_and_default_value_mappings.each_key do |attribute_name|
|
24
|
+
context "for attribute #{attribute_name}" do
|
25
|
+
let(:attribute_name) { attribute_name }
|
26
|
+
let(:new_value) { :dummy_value_for_attribute }
|
27
|
+
|
28
|
+
subject { model.public_send(attribute_name) }
|
29
|
+
|
30
|
+
before do
|
31
|
+
expect(model.public_send(attribute_name)).to_not eq(new_value)
|
32
|
+
model.public_send("#{attribute_name}=", new_value)
|
33
|
+
end
|
34
|
+
|
35
|
+
it {should eq(new_value)}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/http_exception_spec.rb
CHANGED
@@ -8,30 +8,41 @@ describe Http::Exceptions do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe ".wrap_exception" do
|
11
|
-
|
12
|
-
|
13
|
-
described_class.wrap_exception do
|
14
|
-
raise SocketError
|
15
|
-
end
|
16
|
-
end.to raise_error(Http::Exceptions::HttpException)
|
17
|
-
end
|
11
|
+
let(:supported_exception_class) { Http::Exceptions::Configuration::DEFAULT_EXCEPTIONS_TO_CONVERT.first }
|
12
|
+
let(:unsupported_exception_class) { TestException }
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
context "when exception class is supported" do
|
15
|
+
before { expect(Http::Exceptions.configuration.exceptions_to_convert).to include(supported_exception_class) }
|
16
|
+
|
17
|
+
it "raises an HttpException on supported http exceptions" do
|
18
|
+
expect do
|
19
|
+
described_class.wrap_exception do
|
20
|
+
raise supported_exception_class
|
21
|
+
end
|
22
|
+
end.to raise_error(Http::Exceptions::HttpException)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "saves the original exception against the HttpException" do
|
26
|
+
begin
|
27
|
+
described_class.wrap_exception do
|
28
|
+
raise supported_exception_class
|
29
|
+
end
|
30
|
+
rescue Http::Exceptions::HttpException => e
|
31
|
+
expect(e.original_exception).to be_a(supported_exception_class)
|
23
32
|
end
|
24
|
-
rescue Http::Exceptions::HttpException => e
|
25
|
-
expect(e.original_exception).to be_a(SocketError)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
|
-
|
30
|
-
expect
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
context "when exception class is NOT supported" do
|
37
|
+
before { expect(Http::Exceptions.configuration.exceptions_to_convert).to_not include(unsupported_exception_class) }
|
38
|
+
|
39
|
+
it "ignores other exceptions" do
|
40
|
+
expect do
|
41
|
+
described_class.wrap_exception do
|
42
|
+
raise unsupported_exception_class
|
43
|
+
end
|
44
|
+
end.to raise_error(unsupported_exception_class)
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-exceptions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Mathieu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,8 +55,10 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- http-exceptions.gemspec
|
57
57
|
- lib/http/exceptions.rb
|
58
|
+
- lib/http/exceptions/configuration.rb
|
58
59
|
- lib/http/exceptions/http_exception.rb
|
59
60
|
- lib/http/exceptions/version.rb
|
61
|
+
- spec/http/exceptions/configuration_spec.rb
|
60
62
|
- spec/http_exception_spec.rb
|
61
63
|
- spec/spec_helper.rb
|
62
64
|
homepage: ''
|
@@ -79,10 +81,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
81
|
version: '0'
|
80
82
|
requirements: []
|
81
83
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.5.1
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: An easy way to rescue exceptions that might be thrown by your Http library
|
86
88
|
test_files:
|
89
|
+
- spec/http/exceptions/configuration_spec.rb
|
87
90
|
- spec/http_exception_spec.rb
|
88
91
|
- spec/spec_helper.rb
|
92
|
+
has_rdoc:
|