diff --git a/lib/restfulie/client/http/follow_link.rb b/lib/restfulie/client/http/follow_link.rb index 43708c71..b1f8e426 100644 --- a/lib/restfulie/client/http/follow_link.rb +++ b/lib/restfulie/client/http/follow_link.rb @@ -26,7 +26,6 @@ def request!(method, path, *args)#:nodoc: response = delegate(:request!, method, path, *args) rescue Error::Redirection => e response = e.response - debugger if follow_codes.include?(response.code) location = response.headers['location'] || response.headers['Location'] raise Error::AutoFollowWithoutLocationError.new(self, response) unless location diff --git a/lib/restfulie/client/http/request_adapter.rb b/lib/restfulie/client/http/request_adapter.rb index b183625e..1f935147 100644 --- a/lib/restfulie/client/http/request_adapter.rb +++ b/lib/restfulie/client/http/request_adapter.rb @@ -104,14 +104,12 @@ def request!(method, path, *args) response = Restfulie::Client.cache_provider.get([@host, path], http_request, method) return response if response response = http_request.send(method, path, *args) - debugger if path=="/test/701" response = ResponseHandler.handle(method, path, response) rescue Exception => e - Restfulie::Common::Logger.logger.error(e) - raise Error::ServerNotAvailableError.new(self, Response.new(method, path, 503, nil, {}), e ) + response = e end - Restfulie::Client::Response::EnhanceResponse.new(response_handler).parse(@host, path, http_request, self, response) + Restfulie::Client::Response::EnhanceResponse.new(response_handler).parse(@host, path, http_request, self, response, method) end diff --git a/lib/restfulie/client/response/cache_handler.rb b/lib/restfulie/client/response/cache_handler.rb index 8da18f70..18910e2b 100644 --- a/lib/restfulie/client/response/cache_handler.rb +++ b/lib/restfulie/client/response/cache_handler.rb @@ -7,9 +7,11 @@ def initialize(requester) @requester = requester end - def parse(host, path, http_request, request, response) - Restfulie::Client.cache_provider.put([host, path], http_request, response) - @requester.parse(host, path, http_request, request, response) + def parse(host, path, http_request, request, response, method) + unless response.kind_of? Exception + Restfulie::Client.cache_provider.put([host, path], http_request, response) + end + @requester.parse(host, path, http_request, request, response, method) end end end diff --git a/lib/restfulie/client/response/catch_and_throw.rb b/lib/restfulie/client/response/catch_and_throw.rb index 185cb1fc..7fafa065 100644 --- a/lib/restfulie/client/response/catch_and_throw.rb +++ b/lib/restfulie/client/response/catch_and_throw.rb @@ -2,7 +2,11 @@ module Restfulie module Client module Response class CatchAndThrow - def parse(host, path, http_request, request, response) + def parse(host, path, http_request, request, response, method) + if response.kind_of? Exception + Restfulie::Common::Logger.logger.error(response) + raise Restfulie::Client::HTTP::Error::ServerNotAvailableError.new(request, Response.new(method, path, 503, nil, {}), response ) + end case response.code when 100..299 response diff --git a/lib/restfulie/client/response/created_redirect.rb b/lib/restfulie/client/response/created_redirect.rb index acb7ddbc..a57b7900 100644 --- a/lib/restfulie/client/response/created_redirect.rb +++ b/lib/restfulie/client/response/created_redirect.rb @@ -8,8 +8,8 @@ def initialize(config, requester) @requester = requester end - def parse(host, path, http_request, request, response) - result = @requester.parse(host, path, http_request, request, response) + def parse(host, path, http_request, request, response, method) + result = @requester.parse(host, path, http_request, request, response, method) response = result.respond_to?(:response) ? result.response : result if response.respond_to?(:code) && response.code == 201 request = Restfulie.at(response.headers['location']) diff --git a/lib/restfulie/client/response/enhance_response.rb b/lib/restfulie/client/response/enhance_response.rb index 5bf5fb03..b42bf8bb 100644 --- a/lib/restfulie/client/response/enhance_response.rb +++ b/lib/restfulie/client/response/enhance_response.rb @@ -6,8 +6,8 @@ def initialize(requester) @requester = requester end - def parse(host, path, http_request, request, response) - resp = @requester.parse(host, path, http_request, request, response) + def parse(host, path, http_request, request, response, method) + resp = @requester.parse(host, path, http_request, request, response, method) unless resp.kind_of? ::Restfulie::Client::HTTP::ResponseHolder resp.extend(::Restfulie::Client::HTTP::ResponseHolder) resp.response = response diff --git a/lib/restfulie/client/response/ignore_error.rb b/lib/restfulie/client/response/ignore_error.rb index 3fc0a0a6..06c2c32d 100644 --- a/lib/restfulie/client/response/ignore_error.rb +++ b/lib/restfulie/client/response/ignore_error.rb @@ -7,9 +7,9 @@ def initialize(requester) @requester = requester end - def parse(host, path, http_request, request, response) + def parse(host, path, http_request, request, response, method) begin - @requester.parse(host, path, http_request, request, response) + @requester.parse(host, path, http_request, request, response, method) rescue Restfulie::Client::HTTP::Error::RESTError => se se end diff --git a/lib/restfulie/client/response/unmarshall_handler.rb b/lib/restfulie/client/response/unmarshall_handler.rb index 858d9ae7..308fd7e1 100644 --- a/lib/restfulie/client/response/unmarshall_handler.rb +++ b/lib/restfulie/client/response/unmarshall_handler.rb @@ -12,8 +12,8 @@ def initialize(config, requester) # first checks if its a 201, redirecting to the resource location. # otherwise check if its a raw request, returning the content itself. # finally, tries to parse the content with a mediatype handler or returns the response itself. - def parse(host, path, http_request, request, response) - response = @requester.parse(host, path, http_request, request, response) + def parse(host, path, http_request, request, response, method) + response = @requester.parse(host, path, http_request, request, response, method) if @config.raw? response elsif (!response.body.nil?) && !response.body.empty? diff --git a/tests/spec/requests/http/adapter_spec.rb b/tests/spec/requests/http/adapter_spec.rb index cb801324..2b0b73fb 100644 --- a/tests/spec/requests/http/adapter_spec.rb +++ b/tests/spec/requests/http/adapter_spec.rb @@ -340,10 +340,12 @@ class FakeResponse < ::Restfulie::Client::HTTP::Response end it "receives error when 503 code is returned" do - @client.at(nil).get.should respond_with_status(503) + debugger + Restfulie.at("http://localhost:2222/").get.should respond_with_status(503) end + it "raise Error::ServerNotAvailableError error when 503 code is returned" do - lambda { @client.at(nil,nil).get! }.should raise_exception ::Restfulie::Client::HTTP::Error::ServerNotAvailableError + lambda { Restfulie.at("http://localhost:2222/").get! }.should raise_exception ::Restfulie::Client::HTTP::Error::ServerNotAvailableError end it "receives error when 502..599 code is returned" do