net_http_timeout_errors 0.1.0 → 0.2.0
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/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Tired of having to rescue an ever-growing list of Net::HTTP timeout error types?
|
4
4
|
|
5
|
-
Just
|
5
|
+
Just load this gem and then do:
|
6
6
|
|
7
7
|
``` ruby
|
8
8
|
begin
|
@@ -28,6 +28,8 @@ rescue AnotherError, *NetHttpTimeoutErrors.all
|
|
28
28
|
end
|
29
29
|
```
|
30
30
|
|
31
|
+
You can still get at the original error through `NetHttpTimeoutError#original_error`.
|
32
|
+
|
31
33
|
Did we miss an error? Please add it!
|
32
34
|
|
33
35
|
|
@@ -12,10 +12,16 @@ end
|
|
12
12
|
class NetHttpTimeoutErrors
|
13
13
|
def self.all
|
14
14
|
[
|
15
|
+
EOFError,
|
15
16
|
Errno::ECONNREFUSED,
|
16
17
|
Errno::ECONNRESET,
|
17
18
|
Errno::EHOSTUNREACH,
|
19
|
+
Errno::EINVAL,
|
18
20
|
Errno::EPIPE,
|
21
|
+
Errno::ETIMEDOUT,
|
22
|
+
Net::HTTPBadResponse,
|
23
|
+
Net::HTTPHeaderSyntaxError,
|
24
|
+
Net::ProtocolError,
|
19
25
|
SocketError,
|
20
26
|
Timeout::Error,
|
21
27
|
]
|
@@ -3,15 +3,7 @@ require "net_http_timeout_errors"
|
|
3
3
|
|
4
4
|
describe NetHttpTimeoutErrors, ".all" do
|
5
5
|
it "has some" do
|
6
|
-
NetHttpTimeoutErrors.all
|
7
|
-
end
|
8
|
-
|
9
|
-
# No assertions; more like runnable documentation.
|
10
|
-
it "works splatted" do
|
11
|
-
begin
|
12
|
-
raise an_error
|
13
|
-
rescue ZeroDivisionError, *NetHttpTimeoutErrors.all
|
14
|
-
end
|
6
|
+
assert_includes NetHttpTimeoutErrors.all, some_timeout_error
|
15
7
|
end
|
16
8
|
end
|
17
9
|
|
@@ -19,7 +11,7 @@ describe NetHttpTimeoutErrors, ".conflate" do
|
|
19
11
|
it "turns any handled error into a NetHttpTimeoutError" do
|
20
12
|
assert_raises(NetHttpTimeoutError) do
|
21
13
|
NetHttpTimeoutErrors.conflate do
|
22
|
-
raise
|
14
|
+
raise some_timeout_error
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
@@ -35,14 +27,14 @@ describe NetHttpTimeoutErrors, ".conflate" do
|
|
35
27
|
it "keeps the original error" do
|
36
28
|
begin
|
37
29
|
NetHttpTimeoutErrors.conflate do
|
38
|
-
raise
|
30
|
+
raise some_timeout_error
|
39
31
|
end
|
40
32
|
rescue => e
|
41
|
-
assert_instance_of
|
33
|
+
assert_instance_of some_timeout_error, e.original_error
|
42
34
|
end
|
43
35
|
end
|
44
36
|
end
|
45
37
|
|
46
|
-
def
|
47
|
-
|
38
|
+
def some_timeout_error
|
39
|
+
SocketError
|
48
40
|
end
|