rest-client 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/history.md +4 -0
- data/lib/restclient/exceptions.rb +15 -0
- data/spec/exceptions_spec.rb +20 -4
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.1
|
data/history.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
module RestClient
|
2
2
|
|
3
|
+
# Compatibility : make the Response act like a Net::HTTPResponse when needed
|
4
|
+
module ResponseForException
|
5
|
+
def method_missing symbol, *args
|
6
|
+
if net_http_res.respond_to? symbol
|
7
|
+
warn "[warning] The response contained in an RestClient::Exception is now a RestClient::Response instead of a Net::HTTPResponse, please update your code"
|
8
|
+
net_http_res.send symbol, *args
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
# This is the base RestClient exception class. Rescue it if you want to
|
4
16
|
# catch any exception that your request might raise
|
5
17
|
# You can get the status code by e.http_code, or see anything about the
|
@@ -11,6 +23,9 @@ module RestClient
|
|
11
23
|
|
12
24
|
def initialize response = nil
|
13
25
|
@response = response
|
26
|
+
|
27
|
+
# compatibility: this make the exception behave like a Net::HTTPResponse
|
28
|
+
response.extend ResponseForException
|
14
29
|
end
|
15
30
|
|
16
31
|
def http_code
|
data/spec/exceptions_spec.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
|
3
|
+
require 'webmock/rspec'
|
4
|
+
include WebMock
|
5
|
+
|
3
6
|
describe RestClient::Exception do
|
4
7
|
it "sets the exception message to ErrorMessage" do
|
5
8
|
RestClient::ResourceNotFound.new.message.should == 'Resource Not Found'
|
@@ -17,10 +20,11 @@ describe RestClient::RequestFailed do
|
|
17
20
|
end
|
18
21
|
|
19
22
|
it "stores the http response on the exception" do
|
23
|
+
response = "response"
|
20
24
|
begin
|
21
|
-
raise RestClient::RequestFailed,
|
25
|
+
raise RestClient::RequestFailed, response
|
22
26
|
rescue RestClient::RequestFailed => e
|
23
|
-
e.response.should ==
|
27
|
+
e.response.should == response
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
@@ -40,10 +44,11 @@ end
|
|
40
44
|
|
41
45
|
describe RestClient::ResourceNotFound do
|
42
46
|
it "also has the http response attached" do
|
47
|
+
response = "response"
|
43
48
|
begin
|
44
|
-
raise RestClient::ResourceNotFound,
|
49
|
+
raise RestClient::ResourceNotFound, response
|
45
50
|
rescue RestClient::ResourceNotFound => e
|
46
|
-
e.response.should ==
|
51
|
+
e.response.should == response
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -60,4 +65,15 @@ describe "backwards compatibility" do
|
|
60
65
|
it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
|
61
66
|
RestClient::Request::RequestFailed.should == RestClient::RequestFailed
|
62
67
|
end
|
68
|
+
|
69
|
+
it "make the exception's response act like an Net::HTTPResponse" do
|
70
|
+
body = "body"
|
71
|
+
stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
|
72
|
+
begin
|
73
|
+
RestClient.get "www.example.com"
|
74
|
+
raise
|
75
|
+
rescue RestClient::ResourceNotFound => e
|
76
|
+
e.response.body.should == body
|
77
|
+
end
|
78
|
+
end
|
63
79
|
end
|