Commit f7648a9
committed
Remove expand! by raising errors during expand
GitHub: #1
Rather than having separate expand and expand! methods (one swallowing
all exceptions, one not), simplify the API of Embiggen::URI to a single
expand method. This no longer aggressively swallows exceptions outside
of its control but may raise subclasses of Embiggen::Error, namely:
* Embiggen::BadShortenedURI;
* Embiggen::TooManyRedirects;
* Embiggen::NetworkError.
The last of these wraps any network-related exceptions including
timeouts, connection resets, unreachable hosts, etc.
The reason for this change is that these truly are exceptional
circumstances outside of the library's control (unlike, say, an
unshortened URI being passed to Embiggen::URI which can be handled
gracefully). The previous API took too much responsibility away from the
client by silently discarding exceptions by default and therefore
obscuring failures.
Originally, the idea of using a [sum type][0] was appealing (e.g.
returning some sort of result object which could be interrogated for its
success) but this later seemed overengineered and unidiomatic. Instead,
we prefer to return standard Ruby types where appropriate (e.g. standard
library URIs) and raise exceptions in case of failure.
This simplification lead to a refactoring that extracted an HttpClient
class which is currently used privately within the library. This
potentially opens the way for pluggable HTTP clients (rather than being
forced to use Net::HTTP) in future (c.f. #9).
[0]: http://en.wikipedia.org/wiki/Tagged_union1 parent e3632f5 commit f7648a9
File tree
5 files changed
+158
-154
lines changed- lib/embiggen
- spec/embiggen
5 files changed
+158
-154
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
| 47 | + | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
117 | 126 | | |
118 | 127 | | |
119 | 128 | | |
| |||
124 | 133 | | |
125 | 134 | | |
126 | 135 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | 136 | | |
152 | 137 | | |
153 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | | - | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | | - | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 17 | | |
23 | 18 | | |
24 | | - | |
25 | | - | |
| 19 | + | |
| 20 | + | |
26 | 21 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 22 | + | |
| 23 | + | |
32 | 24 | | |
33 | 25 | | |
34 | 26 | | |
| |||
37 | 29 | | |
38 | 30 | | |
39 | 31 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
48 | 36 | | |
49 | | - | |
| 37 | + | |
50 | 38 | | |
51 | 39 | | |
52 | | - | |
| 40 | + | |
53 | 41 | | |
54 | 42 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
76 | 46 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 47 | + | |
80 | 48 | | |
81 | 49 | | |
82 | 50 | | |
0 commit comments