GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/ddollar/rails.git
Added more specific exceptions for 400, 401, and 403 (all descending from 
ClientError so existing rescues will work) (closes #10326) [trek]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8390 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Fri Dec 14 15:09:46 -0800 2007
commit  1ceccdeb7f86898a9e511e934ea6b0863d30590d
tree    51df80c22b0ea40c7893e259884be2204339669e
parent  f5c17790e1a16d92d29f60a5b308b3895e5b94c5
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 [trek]
0
+
0
 * Correct empty response handling. #10445 [seangeo]
0
 
0
 
...
26
27
28
 
 
 
 
 
 
 
 
 
29
30
31
...
110
111
112
 
 
 
 
 
 
113
114
115
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
119
120
121
122
123
124
125
126
127
128
129
130
0
@@ -26,6 +26,15 @@ module ActiveResource
0
   # 4xx Client Error
0
   class ClientError < ConnectionError; end # :nodoc:
0
   
0
+ # 400 Bad Request
0
+ class BadRequest < ClientError; end # :nodoc
0
+
0
+ # 401 Unauthorized
0
+ class UnauthorizedAccess < ClientError; end # :nodoc
0
+
0
+ # 403 Forbidden
0
+ class ForbiddenAccess < ClientError; end # :nodoc
0
+
0
   # 404 Not Found
0
   class ResourceNotFound < ClientError; end # :nodoc:
0
   
0
@@ -110,6 +119,12 @@ module ActiveResource
0
             raise(Redirection.new(response))
0
           when 200...400
0
             response
0
+ when 400
0
+ raise(BadRequest.new(response))
0
+ when 401
0
+ raise(UnauthorizedAccess.new(response))
0
+ when 403
0
+ raise(ForbiddenAccess.new(response))
0
           when 404
0
             raise(ResourceNotFound.new(response))
0
           when 405
...
38
39
40
 
 
 
 
 
 
 
 
 
41
42
43
...
51
52
53
54
 
55
56
57
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
...
60
61
62
 
63
64
65
66
0
@@ -38,6 +38,15 @@ class ConnectionTest < Test::Unit::TestCase
0
       assert_equal expected, handle_response(expected)
0
     end
0
 
0
+ # 400 is a bad request (e.g. malformed URI or missing request parameter)
0
+ assert_response_raises ActiveResource::BadRequest, 400
0
+
0
+ # 401 is an unauthorized request
0
+ assert_response_raises ActiveResource::UnauthorizedAccess, 401
0
+
0
+ # 403 is a forbidden requst (and authorizing will not help)
0
+ assert_response_raises ActiveResource::ForbiddenAccess, 403
0
+
0
     # 404 is a missing resource.
0
     assert_response_raises ActiveResource::ResourceNotFound, 404
0
 
0
@@ -51,7 +60,7 @@ class ConnectionTest < Test::Unit::TestCase
0
     assert_response_raises ActiveResource::ResourceInvalid, 422
0
 
0
     # 4xx are client errors.
0
- [401, 499].each do |code|
0
+ [402, 499].each do |code|
0
       assert_response_raises ActiveResource::ClientError, code
0
     end
0
 

Comments

    No one has commented yet.