ae_network_connection_exception 1.4.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -3
- data/ae_network_connection_exception.gemspec +16 -17
- data/lib/ae_network_connection_exception/version.rb +3 -1
- data/lib/ae_network_connection_exception.rb +22 -28
- metadata +16 -55
- data/.circleci/config.yml +0 -30
- data/.gitignore +0 -16
- data/.ruby-version +0 -1
- data/Appraisals +0 -11
- data/Gemfile +0 -12
- data/README.md +0 -36
- data/Rakefile +0 -24
- data/gemfiles/ruby_2.3.3.gemfile +0 -11
- data/gemfiles/ruby_2.5.3.gemfile +0 -11
- data/test/test_helper.rb +0 -32
- data/test/unit/ae_network_connection_exception_test.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670bacf7b250485b96be28e6623494ea3ef88e93830b27de6c7141d273d53737
|
4
|
+
data.tar.gz: cdcfd66f3fedd185fdb58fc8f6cdd2da0da799ddb22166a1ce270d608c8378fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 371c96edecc48bf85bde49dbe33a12afd216da04f40db63ae9bbbedbdcd200e10fe995467a9d60dc385542f1869e5f39440f77dbc731707cf0555ac1f36f4319
|
7
|
+
data.tar.gz: f0822a534739ba7d31c14b37873236d41c6a8adae6714ecd86f50ae95ee01ea800576963b158fee142ef88349fb3785f4dec8ec21addaeabf220cc851783baa1
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
#
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'ae_network_connection_exception/version'
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
spec.name = "ae_network_connection_exception"
|
8
|
-
spec.version = AeNetworkConnectionException::VERSION
|
9
|
-
spec.authors = ["Steven Boyd"]
|
10
|
-
spec.email = ["engineering@appfolio.com"]
|
11
|
-
spec.summary = "Provides sane exceptions for network failures"
|
12
|
-
spec.description = "A simple gem that will catch all manner of exceptions related to establishing a network connection and return a more generic error."
|
13
|
-
spec.homepage = "http://github.com/appfolio/ae_network_connection_exception"
|
14
|
-
spec.license = "MIT"
|
3
|
+
require_relative 'lib/ae_network_connection_exception/version'
|
15
4
|
|
16
|
-
|
17
|
-
spec.
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ae_network_connection_exception'
|
7
|
+
spec.version = AeNetworkConnectionException::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.author = 'AppFolio'
|
10
|
+
spec.email = 'opensource@appfolio.com'
|
11
|
+
spec.description = 'Catch exceptions related to establishing a network connection and return a generic error.'
|
12
|
+
spec.summary = 'Provides sane exceptions for network failures.'
|
13
|
+
spec.homepage = 'https://github.com/appfolio/ae_network_connection_exception'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = Dir['**/*'].select { |f| f[%r{^(lib/|LICENSE.txt|.*gemspec)}] }
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.3')
|
18
18
|
|
19
|
-
spec.
|
20
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
20
|
end
|
@@ -1,38 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'socket'
|
4
5
|
|
5
6
|
module AeNetworkConnectionException
|
6
7
|
class ConnectionNotEstablished < StandardError
|
7
8
|
end
|
8
9
|
|
9
|
-
OTHER_EXCEPTIONS = []
|
10
|
-
if defined?(RestClient::Exceptions::OpenTimeout)
|
11
|
-
puts "here"
|
12
|
-
OTHER_EXCEPTIONS << RestClient::Exceptions::OpenTimeout
|
13
|
-
end
|
14
|
-
OTHER_EXCEPTIONS.freeze
|
15
|
-
|
16
10
|
class << self
|
17
11
|
def try
|
18
12
|
yield
|
19
|
-
rescue SocketError, Net::OpenTimeout, *
|
20
|
-
# SocketError happens when we fail to connect to a socket.
|
21
|
-
#
|
22
|
-
|
13
|
+
rescue SocketError, Net::OpenTimeout, *other_exceptions
|
14
|
+
# SocketError happens when we fail to connect to a socket.
|
15
|
+
# Common problems here are DNS resolution (i.e. getaddrinfo).
|
16
|
+
# Net::OpenTimeout happens when we are unable to establish an HTTP connection before the open_timeout.
|
23
17
|
raise ConnectionNotEstablished
|
24
18
|
rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH => e
|
25
|
-
# Errno::ECONNREFUSED happens when we can not connect to the port
|
26
|
-
# Errno::ETIMEDOUT happens when we timeout durring the tcp handshake
|
27
|
-
#
|
19
|
+
# Errno::ECONNREFUSED happens when we can not connect to the port.
|
20
|
+
# Errno::ETIMEDOUT happens when we timeout durring the tcp handshake.
|
21
|
+
# Errno::ETIMEDOUT can also happen after we have established a connection and are waiting for a response.
|
28
22
|
# Because of this, we also check that the sys call that was made is connect(2).
|
29
|
-
# Errno::* Exceptions have the following error message format
|
30
|
-
#
|
31
|
-
|
23
|
+
# Errno::* Exceptions have the following error message format:
|
24
|
+
# "#{Message string} - #{syscall} for "#{host}" port #{port}"
|
32
25
|
raise_if_exception_message_matches(e, /connect\(2\)/)
|
33
26
|
rescue Errno::ECONNRESET => e
|
34
|
-
# Errno::ECONNRESET happens when the connection is reset. This can happen during
|
35
|
-
|
27
|
+
# Errno::ECONNRESET happens when the connection is reset. This can happen during SSL negotiation.
|
36
28
|
raise_if_exception_message_matches(e, /SSL_connect/)
|
37
29
|
end
|
38
30
|
|
@@ -43,7 +35,7 @@ module AeNetworkConnectionException
|
|
43
35
|
Errno::ECONNREFUSED.new('Connection refused - connect(2) for "example.com" port 443'),
|
44
36
|
Errno::ETIMEDOUT.new('Connection timed out - connect(2) for "example.com" port 443'),
|
45
37
|
Net::OpenTimeout.new('message'),
|
46
|
-
Errno::ECONNRESET.new('Connection reset by peer - SSL_connect'
|
38
|
+
Errno::ECONNRESET.new('Connection reset by peer - SSL_connect'),
|
47
39
|
Errno::EHOSTUNREACH.new('No route to host - connect(2) for "example.com" port 443'),
|
48
40
|
Errno::ENETUNREACH.new('Network is unreachable - connect(2) for "example.com" port 443')
|
49
41
|
]
|
@@ -51,12 +43,14 @@ module AeNetworkConnectionException
|
|
51
43
|
|
52
44
|
private
|
53
45
|
|
46
|
+
def other_exceptions
|
47
|
+
defined?(RestClient::Exceptions::OpenTimeout) ? [RestClient::Exceptions::OpenTimeout] : []
|
48
|
+
end
|
49
|
+
|
54
50
|
def raise_if_exception_message_matches(exception, pattern)
|
55
|
-
if exception.message =~ pattern
|
56
|
-
|
57
|
-
|
58
|
-
raise exception
|
59
|
-
end
|
51
|
+
raise ConnectionNotEstablished if exception.message =~ pattern
|
52
|
+
|
53
|
+
raise exception
|
60
54
|
end
|
61
55
|
end
|
62
56
|
end
|
metadata
CHANGED
@@ -1,71 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_network_connection_exception
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- AppFolio
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.7'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.0'
|
41
|
-
description: A simple gem that will catch all manner of exceptions related to establishing
|
42
|
-
a network connection and return a more generic error.
|
43
|
-
email:
|
44
|
-
- engineering@appfolio.com
|
11
|
+
date: 2022-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Catch exceptions related to establishing a network connection and return
|
14
|
+
a generic error.
|
15
|
+
email: opensource@appfolio.com
|
45
16
|
executables: []
|
46
17
|
extensions: []
|
47
18
|
extra_rdoc_files: []
|
48
19
|
files:
|
49
|
-
- ".circleci/config.yml"
|
50
|
-
- ".gitignore"
|
51
|
-
- ".ruby-version"
|
52
|
-
- Appraisals
|
53
|
-
- Gemfile
|
54
20
|
- LICENSE.txt
|
55
|
-
- README.md
|
56
|
-
- Rakefile
|
57
21
|
- ae_network_connection_exception.gemspec
|
58
|
-
- gemfiles/ruby_2.3.3.gemfile
|
59
|
-
- gemfiles/ruby_2.5.3.gemfile
|
60
22
|
- lib/ae_network_connection_exception.rb
|
61
23
|
- lib/ae_network_connection_exception/version.rb
|
62
|
-
|
63
|
-
- test/unit/ae_network_connection_exception_test.rb
|
64
|
-
homepage: http://github.com/appfolio/ae_network_connection_exception
|
24
|
+
homepage: https://github.com/appfolio/ae_network_connection_exception
|
65
25
|
licenses:
|
66
26
|
- MIT
|
67
|
-
metadata:
|
68
|
-
|
27
|
+
metadata:
|
28
|
+
allowed_push_host: https://rubygems.org
|
29
|
+
post_install_message:
|
69
30
|
rdoc_options: []
|
70
31
|
require_paths:
|
71
32
|
- lib
|
@@ -73,15 +34,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
34
|
requirements:
|
74
35
|
- - ">="
|
75
36
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
37
|
+
version: 2.6.3
|
77
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
39
|
requirements:
|
79
40
|
- - ">="
|
80
41
|
- !ruby/object:Gem::Version
|
81
42
|
version: '0'
|
82
43
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
84
|
-
signing_key:
|
44
|
+
rubygems_version: 3.3.3
|
45
|
+
signing_key:
|
85
46
|
specification_version: 4
|
86
|
-
summary: Provides sane exceptions for network failures
|
47
|
+
summary: Provides sane exceptions for network failures.
|
87
48
|
test_files: []
|
data/.circleci/config.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
defaults: &defaults
|
2
|
-
working_directory: ~/repo
|
3
|
-
|
4
|
-
steps:
|
5
|
-
- checkout
|
6
|
-
- run: bundle install
|
7
|
-
- run: bundle exec appraisal install
|
8
|
-
- run: bundle exec appraisal rake test
|
9
|
-
|
10
|
-
version: 2
|
11
|
-
jobs:
|
12
|
-
test-ruby-2.3.3:
|
13
|
-
<<: *defaults
|
14
|
-
docker:
|
15
|
-
- image: circleci/ruby:2.3.3
|
16
|
-
|
17
|
-
test-ruby-2.5.3:
|
18
|
-
<<: *defaults
|
19
|
-
docker:
|
20
|
-
- image: circleci/ruby:2.5.3-stretch
|
21
|
-
|
22
|
-
workflows:
|
23
|
-
version: 2
|
24
|
-
rc:
|
25
|
-
jobs:
|
26
|
-
- test-ruby-2.3.3:
|
27
|
-
context: appfolio_test_context
|
28
|
-
- test-ruby-2.5.3:
|
29
|
-
context: appfolio_test_context
|
30
|
-
|
data/.gitignore
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.3.3
|
data/Appraisals
DELETED
data/Gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in ae_network_connection_exception.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'minitest', '~> 5.0'
|
7
|
-
|
8
|
-
source 'https://gemini.atl.appfolio.net' do
|
9
|
-
gem 'af_gems'
|
10
|
-
end
|
11
|
-
|
12
|
-
gem 'rest-client', '~> 2.0', require: false
|
data/README.md
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# AeNetworkConnectionException
|
2
|
-
|
3
|
-
A simple gem that will catch all manner of exceptions related to establishing a network connection and return a more generic error.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'ae_network_connection_exception'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install ae_network_connection_exception
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
```
|
23
|
-
AeNetworkConnectionException.try do
|
24
|
-
# your code that will make a network call
|
25
|
-
end
|
26
|
-
```
|
27
|
-
|
28
|
-
If your network call failed to establise a network connection, an exception of type ```AeNetworkConnectionException::ConnectionNotEstablished``` will be thrown
|
29
|
-
|
30
|
-
## Contributing
|
31
|
-
|
32
|
-
1. Fork it ( https://github.com/appfolio/ae_network_connection_exception/fork )
|
33
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
-
5. Create a new Pull Request
|
data/Rakefile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'af_gems/gem_tasks'
|
12
|
-
require 'af_gems/appraisal'
|
13
|
-
|
14
|
-
Rake::TestTask.new(:test) do |test|
|
15
|
-
test.libs << 'lib' << 'test'
|
16
|
-
test.pattern = 'test/unit/**/*_test.rb'
|
17
|
-
test.verbose = true
|
18
|
-
end
|
19
|
-
|
20
|
-
task :default => :test
|
21
|
-
|
22
|
-
namespace :test do
|
23
|
-
AfGems::RubyAppraisalTask.new(:all, [ 'ruby-2.3.3', 'ruby-2.5.3' ])
|
24
|
-
end
|
data/gemfiles/ruby_2.3.3.gemfile
DELETED
data/gemfiles/ruby_2.5.3.gemfile
DELETED
data/test/test_helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'ae_network_connection_exception'
|
4
|
-
|
5
|
-
private
|
6
|
-
|
7
|
-
class Minitest::Test
|
8
|
-
def assert_connection_not_established_thrown_for(exception)
|
9
|
-
e = return_raised_error do
|
10
|
-
AeNetworkConnectionException.try do
|
11
|
-
raise exception
|
12
|
-
end
|
13
|
-
end
|
14
|
-
assert_equal AeNetworkConnectionException::ConnectionNotEstablished, e.class
|
15
|
-
assert_equal exception, e.cause
|
16
|
-
end
|
17
|
-
|
18
|
-
def assert_connection_not_established_not_thrown_for(exception)
|
19
|
-
e = return_raised_error do
|
20
|
-
AeNetworkConnectionException.try do
|
21
|
-
raise exception
|
22
|
-
end
|
23
|
-
end
|
24
|
-
assert_equal exception, e
|
25
|
-
end
|
26
|
-
|
27
|
-
def return_raised_error
|
28
|
-
yield
|
29
|
-
rescue => e
|
30
|
-
return e
|
31
|
-
end
|
32
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'rest-client'
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
module AeNetworkConnectionException
|
5
|
-
class AeNetworkConnectionExceptionTest < Minitest::Test
|
6
|
-
def test_connection_not_established_exception
|
7
|
-
# Exception Causes are standard with ruby 2.1
|
8
|
-
# http://devblog.avdi.org/2013/12/25/exception-causes-in-ruby-2-1
|
9
|
-
|
10
|
-
parent_exception = AeNetworkConnectionException::ConnectionNotEstablished.new('Parent Message')
|
11
|
-
|
12
|
-
assert_nil parent_exception.cause
|
13
|
-
assert_equal 'Parent Message', parent_exception.message
|
14
|
-
|
15
|
-
begin
|
16
|
-
child_exception = nil
|
17
|
-
begin
|
18
|
-
raise StandardError.new('New Child Message')
|
19
|
-
rescue => e
|
20
|
-
child_exception = e
|
21
|
-
parent_exception = AeNetworkConnectionException::ConnectionNotEstablished.new('New Parent Message')
|
22
|
-
end
|
23
|
-
rescue AeNetworkConnectionException::ConnectionNotEstablished => parent_exception
|
24
|
-
|
25
|
-
refute_nil child_exception
|
26
|
-
assert_equal child_exception, parent_exception.cause
|
27
|
-
assert_equal 'New Parent Message, cause => StandardError: New Child Message', parent_exception.message
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_ae_network_connection_exception_try__doesnt_catch_non_network_exceptions
|
32
|
-
exception = StandardError.new
|
33
|
-
e = return_raised_error do
|
34
|
-
AeNetworkConnectionException.try do
|
35
|
-
raise exception
|
36
|
-
end
|
37
|
-
end
|
38
|
-
assert_equal exception, e
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_ae_network_connection_exception_try__raises_connection_not_establised_exception
|
42
|
-
AeNetworkConnectionException.exception_signatures.each do |e|
|
43
|
-
assert_connection_not_established_thrown_for(e)
|
44
|
-
end
|
45
|
-
|
46
|
-
assert_connection_not_established_not_thrown_for(Errno::ECONNRESET.new('Connection timed out - connect(2) for "example.com" port 443'))
|
47
|
-
assert_connection_not_established_not_thrown_for(Errno::ETIMEDOUT.new('Connection timed out - recvfrom(2) for "example.com" port 443'))
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_ae_network_connection_exception_try__raises_connection_not_establised_exception_for_rest_client_open_timeout
|
51
|
-
assert_connection_not_established_thrown_for(RestClient::Exceptions::OpenTimeout.new)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_exception_signatures
|
55
|
-
expected_signatures = [
|
56
|
-
SocketError.new('getaddrinfo: Name or service not known'),
|
57
|
-
Errno::ECONNREFUSED.new('Connection refused - connect(2) for "example.com" port 443'),
|
58
|
-
Errno::ETIMEDOUT.new('Connection timed out - connect(2) for "example.com" port 443'),
|
59
|
-
Net::OpenTimeout.new('message'),
|
60
|
-
Errno::ECONNRESET.new('Connection reset by peer - SSL_connect', Errno::ECONNREFUSED.new('Connection refused - connect(2) for "example.com" port 443')),
|
61
|
-
Errno::EHOSTUNREACH.new('No route to host - connect(2) for "example.com" port 443'),
|
62
|
-
Errno::ENETUNREACH.new('Network is unreachable - connect(2) for "example.com" port 443')
|
63
|
-
]
|
64
|
-
|
65
|
-
assert_equal expected_signatures.size, AeNetworkConnectionException.exception_signatures.size
|
66
|
-
|
67
|
-
expected_signatures.each do |e|
|
68
|
-
assert_includes AeNetworkConnectionException.exception_signatures, e
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|