lib/cfoundry/v1/base.rb in cfoundry-0.4.18 vs lib/cfoundry/v1/base.rb in cfoundry-0.4.19

- old
+ new

@@ -99,40 +99,20 @@ retry end private - def handle_response(response, accept) - case response - when Net::HTTPSuccess, Net::HTTPRedirection - if accept == :json - if response.is_a?(Net::HTTPNoContent) - raise CFoundry::BadResponse.new( - 204, - "Expected JSON response, got 204 No Content") - end + def handle_response(response, accept, request) + # this is a copy paste of v2 + return super if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) - parse_json(response.body) - else - response.body - end + info = parse_json(response.body) + return super unless info[:code] - when Net::HTTPBadRequest, Net::HTTPForbidden, Net::HTTPNotFound, - Net::HTTPInternalServerError, Net::HTTPNotImplemented, - Net::HTTPBadGateway - begin - info = parse_json(response.body) - return super unless info[:code] + cls = CFoundry::APIError.error_classes[info[:code]] - cls = CFoundry::APIError.error_classes[info[:code]] - - raise (cls || CFoundry::APIError).new(info[:code], info[:description]) - rescue MultiJson::DecodeError - super - end - - else - super - end + raise (cls || CFoundry::APIError).new(request, response, info[:description], info[:code]) + rescue MultiJson::DecodeError + super end end end