ae_network_connection_exception 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69c47de028f1f0de4f3625fdf83a28fca3d6bbd1
4
+ data.tar.gz: 27cbec84b9eaa7002eacaba19b3ace203a8d2b85
5
+ SHA512:
6
+ metadata.gz: d62132d7ed9febb5a1e1fe2eb0bbac4c33273708161ebad9731f1a1226ac699516c52434b2c29c3517f1493f239a17da11bdb685136aa36f6e071c0a8640a88b
7
+ data.tar.gz: ca6a7edd4917f54e299ff3374c42e5a74f8a81d31bde26530c471a3d4d3f69ac1f1a234400a2a89a4e6ac2ebe266de6c212961c6f62f643c178d5a5b47694bf2
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ae_network_connection_exception.gemspec
4
+ gemspec
5
+
6
+ gem 'test-unit'
7
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 AppFolio, inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
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
+ # If your network call failed to establise a network connection, an exception of type ```AeNetworkConnectionException::ConnectionNotEstablished``` will be thrown
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/appfolio/ae_network_connection_exception/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/unit/**/*_test.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ae_network_connection_exception/version'
5
+
6
+ Gem::Specification.new do |spec|
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"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,37 @@
1
+ require "ae_network_connection_exception/version"
2
+ require "socket"
3
+
4
+ module AeNetworkConnectionException
5
+
6
+ class ConnectionNotEstablished < StandardError
7
+ attr_reader :cause
8
+
9
+ def initialize(message = nil, cause = $!)
10
+ super(message)
11
+ @cause = cause
12
+ end
13
+
14
+ def message
15
+ own_message = super
16
+
17
+ if cause
18
+ message = "#{own_message}, "
19
+ message + "cause => #{cause.class}: #{cause.message}"
20
+ else
21
+ own_message
22
+ end
23
+ end
24
+ end
25
+
26
+ def self.try
27
+ yield
28
+ rescue SocketError => e
29
+ raise ConnectionNotEstablished
30
+ rescue SystemCallError => e
31
+ if ([Errno::ETIMEDOUT, Errno::ECONNREFUSED].include? e.class) && (e.message =~ /connect\(2\)/)
32
+ raise ConnectionNotEstablished
33
+ else
34
+ raise e
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module AeNetworkConnectionException
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
4
+
5
+ require 'rubygems'
6
+ require 'test/unit'
7
+ require 'ae_network_connection_exception'
8
+
@@ -0,0 +1,93 @@
1
+ require 'test_helper'
2
+
3
+ module AeNetworkConnectionException
4
+ class AeNetworkConnectionExceptionTest < Test::Unit::TestCase
5
+ def test_connection_not_established_exception
6
+ parent_exception = AeNetworkConnectionException::ConnectionNotEstablished.new("Parent Message")
7
+
8
+ assert_equal nil, parent_exception.cause
9
+ assert_equal "Parent Message", parent_exception.message
10
+
11
+ child_exception = StandardError.new("Child Message")
12
+ parent_exception = AeNetworkConnectionException::ConnectionNotEstablished.new("Parent Message", child_exception)
13
+
14
+ assert_equal child_exception, parent_exception.cause
15
+ assert_equal "Parent Message, cause => StandardError: Child Message", parent_exception.message
16
+
17
+ child_exception = nil
18
+ parent_exception = nil
19
+ begin
20
+ raise StandardError.new("New Child Message")
21
+ rescue => e
22
+ child_exception = e
23
+ parent_exception = AeNetworkConnectionException::ConnectionNotEstablished.new("New Parent Message")
24
+ end
25
+
26
+ assert_not_nil child_exception
27
+ assert_equal child_exception, parent_exception.cause
28
+ assert_equal "New Parent Message, cause => StandardError: New Child Message", parent_exception.message
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
+ e = return_raised_error do
43
+ AeNetworkConnectionException.try do
44
+ raise SocketError.new("getaddrinfo: Name or service not known")
45
+ end
46
+ end
47
+ assert_equal AeNetworkConnectionException::ConnectionNotEstablished, e.class
48
+ assert_equal SocketError, e.cause.class
49
+
50
+ e = return_raised_error do
51
+ AeNetworkConnectionException.try do
52
+ raise Errno::ECONNREFUSED.new('Connection refused - connect(2) for "example.com" port 443')
53
+ end
54
+ end
55
+ assert_equal AeNetworkConnectionException::ConnectionNotEstablished, e.class
56
+ assert_equal Errno::ECONNREFUSED, e.cause.class
57
+
58
+ e = return_raised_error do
59
+ AeNetworkConnectionException.try do
60
+ raise Errno::ETIMEDOUT.new('Connection timed out - connect(2) for "example.com" port 443')
61
+ end
62
+ end
63
+ assert_equal AeNetworkConnectionException::ConnectionNotEstablished, e.class
64
+ assert_equal Errno::ETIMEDOUT, e.cause.class
65
+
66
+
67
+
68
+ e = return_raised_error do
69
+ AeNetworkConnectionException.try do
70
+ raise Errno::ECONNRESET.new('Connection timed out - connect(2) for "example.com" port 443')
71
+ end
72
+ end
73
+ assert_equal Errno::ECONNRESET, e.class
74
+
75
+ e = return_raised_error do
76
+ AeNetworkConnectionException.try do
77
+ raise Errno::ETIMEDOUT.new('Connection timed out - recvfrom(2) for "example.com" port 443')
78
+ end
79
+ end
80
+ assert_equal Errno::ETIMEDOUT, e.class
81
+
82
+ end
83
+
84
+ private
85
+
86
+ def return_raised_error
87
+ yield
88
+ rescue => e
89
+ return e
90
+ end
91
+ end
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ae_network_connection_exception
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Boyd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
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
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - ae_network_connection_exception.gemspec
55
+ - lib/ae_network_connection_exception.rb
56
+ - lib/ae_network_connection_exception/version.rb
57
+ - test/test_helper.rb
58
+ - test/unit/ae_network_connection_exception_test.rb
59
+ homepage: http://github.com/appfolio/ae_network_connection_exception
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Provides sane exceptions for network failures
83
+ test_files:
84
+ - test/test_helper.rb
85
+ - test/unit/ae_network_connection_exception_test.rb
86
+ has_rdoc: