From 31b72b42f24f82e4c2850e5942ee97e8dafab1f5 Mon Sep 17 00:00:00 2001 From: Brad Gignac Date: Thu, 31 Jan 2013 21:50:58 -0500 Subject: [PATCH] [rackspace|compute] Handle malformed API responses. When deleting a Cloud Network, the API returns a plain text response even when the Content-Type is set to application/json. In the event of a JSON parsing error, this change sets the request body to an empty hash. --- lib/fog/rackspace/compute_v2.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fog/rackspace/compute_v2.rb b/lib/fog/rackspace/compute_v2.rb index c12ba504e..164768591 100644 --- a/lib/fog/rackspace/compute_v2.rb +++ b/lib/fog/rackspace/compute_v2.rb @@ -127,8 +127,13 @@ module Fog rescue Excon::Errors::HTTPStatusError => error raise ServiceError.slurp error end + unless response.body.empty? - response.body = Fog::JSON.decode(response.body) + begin + response.body = Fog::JSON.decode(response.body) + rescue MultiJson::DecodeError => e + response.body = {} + end end response end