lib/heroku/api.rb in heroku-api-0.3.11 vs lib/heroku/api.rb in heroku-api-0.3.12

- old
+ new

@@ -91,19 +91,18 @@ when 429 then Heroku::API::Errors::RateLimitExceeded when /50./ then Heroku::API::Errors::RequestFailed else Heroku::API::Errors::ErrorWithResponse end + decompress_response!(error.response) reerror = klass.new(error.message, error.response) reerror.set_backtrace(error.backtrace) raise(reerror) end if response.body && !response.body.empty? - if response.headers['Content-Encoding'] == 'gzip' - response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read - end + decompress_response!(response) begin response.body = Heroku::API::OkJson.decode(response.body) rescue # leave non-JSON body as is end @@ -114,9 +113,14 @@ response end private + + def decompress_response!(response) + return unless response.headers['Content-Encoding'] == 'gzip' + response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read + end def app_params(params) app_params = {} params.each do |key, value| app_params["app[#{key}]"] = value