net_http_exception_fix 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +73 -0
- data/Rakefile +15 -0
- data/lib/net_http_exception_fix.rb +9 -0
- data/lib/net_http_exception_fix/version.rb +3 -0
- data/net_http_exception_fix.gemspec +20 -0
- data/test/test_net_http_exception_fix.rb +18 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
= Net::HTTP Exception Fix
|
2
|
+
|
3
|
+
Using Net::HTTP can lead to headaches when it comes to rescuing all the different kinds of exceptions it might raise.
|
4
|
+
|
5
|
+
This is a hotfix to give those common exceptions that pop up from Net:HTTP usage a shared parent exception class.
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
require 'net_http_exception_fix'
|
10
|
+
|
11
|
+
begin
|
12
|
+
response = Net::HTTP.get_response(uri)
|
13
|
+
rescue Net::HTTPBroken => e
|
14
|
+
...
|
15
|
+
end
|
16
|
+
|
17
|
+
== Thanks
|
18
|
+
|
19
|
+
Mad props to Tammer Saleh [1] and all the find folks on Stack Overflow [2] who confirmed my WTFness when it comes to handling Net::HTTP exceptions right.
|
20
|
+
|
21
|
+
[1] http://tammersaleh.com/posts/rescuing-net-http-exceptions
|
22
|
+
[2] http://stackoverflow.com/questions/5370697/whats-the-best-way-to-handle-exceptions-from-nethttp
|
23
|
+
|
24
|
+
== Running tests
|
25
|
+
|
26
|
+
Run the tests with
|
27
|
+
|
28
|
+
$ rake test
|
29
|
+
|
30
|
+
== Download
|
31
|
+
|
32
|
+
Currently this library is available with git from:
|
33
|
+
|
34
|
+
git://github.com/edward/net_http_exception_fix.git
|
35
|
+
|
36
|
+
== Installation
|
37
|
+
|
38
|
+
=== From Git
|
39
|
+
|
40
|
+
You can check out the latest source from git:
|
41
|
+
|
42
|
+
> git pull git://github.com/edward/net_http_exception_fix.git
|
43
|
+
|
44
|
+
=== From Ruby Gems
|
45
|
+
|
46
|
+
Installation from RubyGems
|
47
|
+
|
48
|
+
> gem install net_http_exception_fix
|
49
|
+
|
50
|
+
== Author
|
51
|
+
|
52
|
+
Edward Ocampo-Gooding <edward@edwardog.net>
|
53
|
+
|
54
|
+
== Copyright
|
55
|
+
|
56
|
+
Copyright (C) 2011 Edward Ocampo-Gooding
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
59
|
+
of this software and associated documentation files (the "Software"), to
|
60
|
+
deal in the Software without restriction, including without limitation the
|
61
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
62
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
63
|
+
furnished to do so, subject to the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be included in
|
66
|
+
all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
69
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
70
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
71
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
72
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
73
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'bundler'
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
task :default => [:test]
|
9
|
+
|
10
|
+
desc "Run tests"
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
12
|
+
t.pattern = 'test/test_*.rb'
|
13
|
+
t.verbose = true
|
14
|
+
t.warning = true
|
15
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Net::HTTPBroken; end
|
4
|
+
|
5
|
+
[Timeout::Error, Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET,
|
6
|
+
Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse,
|
7
|
+
Net::HTTPHeaderSyntaxError, Net::ProtocolError].each do |m|
|
8
|
+
m.send(:include, Net::HTTPBroken)
|
9
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "net_http_exception_fix/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "net_http_exception_fix"
|
7
|
+
s.version = NetHttpExceptionFix::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Edward Ocampo-Gooding", "Tammer Saleh"]
|
10
|
+
s.email = ["edward@edwardog.net"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Adds Net::HTTPBroken as a blanket exception you can rescue from when making Net::HTTP calls}
|
13
|
+
s.description = %q{Slips Net::HTTPBroken into the inheritance ancestry of common exceptions Net::HTTP tends to raise.}
|
14
|
+
s.rubyforge_project = "net_http_exception_fix"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'net_http_exception_fix'
|
3
|
+
|
4
|
+
class TestNetHttpExceptionFix < Test::Unit::TestCase
|
5
|
+
def test_valid_exception
|
6
|
+
assert_raise Net::HTTPBroken do
|
7
|
+
raise Net::HTTPBadResponse
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_invalid_exception
|
12
|
+
begin
|
13
|
+
raise Errno::EACCES
|
14
|
+
rescue StandardError => e
|
15
|
+
assert !e.is_a?(Net::HTTPBroken)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net_http_exception_fix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edward Ocampo-Gooding
|
9
|
+
- Tammer Saleh
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-03-20 00:00:00 -04:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description: Slips Net::HTTPBroken into the inheritance ancestry of common exceptions Net::HTTP tends to raise.
|
19
|
+
email:
|
20
|
+
- edward@edwardog.net
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- .gitignore
|
29
|
+
- Gemfile
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- lib/net_http_exception_fix.rb
|
33
|
+
- lib/net_http_exception_fix/version.rb
|
34
|
+
- net_http_exception_fix.gemspec
|
35
|
+
- test/test_net_http_exception_fix.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: ""
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: net_http_exception_fix
|
60
|
+
rubygems_version: 1.6.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Adds Net::HTTPBroken as a blanket exception you can rescue from when making Net::HTTP calls
|
64
|
+
test_files:
|
65
|
+
- test/test_net_http_exception_fix.rb
|