aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-08-09 19:22:04 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-08-09 19:22:04 +0000
commit18a4cc1bd2d260c6905b58dee61e7b3ac88f0a6b (patch)
treed1b048c408df044817bd31fa878fb09fab87507b /activeresource/lib
parentd4bf5e9b34d8d57be49ac50e31d6ad4151e43947 (diff)
downloadrails-18a4cc1bd2d260c6905b58dee61e7b3ac88f0a6b.tar.gz
rails-18a4cc1bd2d260c6905b58dee61e7b3ac88f0a6b.tar.bz2
rails-18a4cc1bd2d260c6905b58dee61e7b3ac88f0a6b.zip
Raise ActiveResource::Redirection on 301,302 http code
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7297 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib')
-rw-r--r--activeresource/lib/active_resource/connection.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index 5aef6f4d42..07f3c98eda 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -14,10 +14,15 @@ module ActiveResource
end
def to_s
- "Failed with #{response.code}"
+ "Failed with #{response.code} #{response.message if response.respond_to?(:message)}"
end
end
+ # 3xx Redirection
+ class Redirection < ConnectionError # :nodoc:
+ def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
+ end
+
# 4xx Client Error
class ClientError < ConnectionError; end # :nodoc:
@@ -107,6 +112,8 @@ module ActiveResource
# Handles response and error codes from remote service.
def handle_response(response)
case response.code.to_i
+ when 301,302
+ raise(Redirection.new(response))
when 200...400
response
when 404