http-exceptions 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rvmrc +1 -0
- data/README.md +23 -7
- data/lib/http/exceptions/version.rb +1 -1
- data/lib/http/exceptions.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ffca1fda1f057ce3a70dc47630a23fd567de208
|
4
|
+
data.tar.gz: 19c46b249e069e3e5c5ce90b39edf979e23a62f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cfbced68908a3db07560fd8fe00104b3fe5e2167b52368d272b4f4d199911fcebf149ce6d8fa8fd1a32aac3897a64411f176d2f90ed23bc412e60aab551f0a9
|
7
|
+
data.tar.gz: 15a95d10cd078497d30925bddd477ae76bb96a420001815019a4921500ea9e931ccb917089caa66fe59df42c506e83045de8e928dd5e4697b29610569444cd46
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.1.2@http-exceptions --create
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Http::Exceptions provides an easy way to rescue exceptions that might be thrown by your Http library.
|
4
4
|
|
5
|
+
If you're using a library such as the excellent [HTTParty](https://github.com/jnunemaker/httparty), you still have to deal with various types of exceptions. In an ideal world, the return code of the HTTP request would be the sole indicator of failures, but HTTP libraries can raise a large number of exceptions (such as `SocketError` or `Net::ReadTimeout`) that you need to handle.
|
6
|
+
|
7
|
+
Http::Exceptions converts any error that might be raised by your HTTP library and wrap it in a `Http::Exceptions::HttpException`.
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -21,26 +25,38 @@ Or install it yourself as:
|
|
21
25
|
Only rescue raised exceptions.
|
22
26
|
|
23
27
|
```ruby
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
response = Http::Exceptions.wrap_exception do
|
29
|
+
HTTParty.get "http://www.google.com"
|
30
|
+
end
|
27
31
|
```
|
28
32
|
|
29
33
|
Raise an exception is the return code of the API call is not `2XX`.
|
30
34
|
|
31
35
|
```ruby
|
32
|
-
|
33
|
-
|
36
|
+
response = Http::Exceptions.wrap_and_check do
|
37
|
+
HTTParty.get "http://www.google.com"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
You can then rescue the exception in the following way:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
begin
|
45
|
+
response = Http::Exceptions.wrap_and_check do
|
46
|
+
HTTParty.get "http://www.google.com"
|
34
47
|
end
|
48
|
+
rescue Http::Exceptions::HttpException => e
|
49
|
+
# ...
|
50
|
+
end
|
35
51
|
```
|
36
52
|
|
37
53
|
### Support
|
38
54
|
|
39
|
-
Currently, this only has been tested with
|
55
|
+
Currently, this only has been tested with HTTParty. It should however work with any library that delegates to the ruby http library.
|
40
56
|
|
41
57
|
## Contributing
|
42
58
|
|
43
|
-
1. Fork it ( https://github.com/
|
59
|
+
1. Fork it ( https://github.com/rainforestapp/http-exceptions/fork )
|
44
60
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
61
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
62
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/http/exceptions.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-exceptions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Mathieu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
+
- ".rvmrc"
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|