Class: CloudFoundry::Client::Response::ParseJSON

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/cloudfoundry/client/response.rb

Overview

Faraday Response Middleware to parse cloud JSON responses.

Instance Method Summary collapse

Instance Method Details

#parse(body) ⇒ Hash

Parses a JSON response.

Parameters:

  • body (String)

    HTTP body response.

Returns:

  • (Hash)

    Parsed body response with symbolized names (keys).

Raises:



12
13
14
15
16
17
18
19
# File 'lib/cloudfoundry/client/response.rb', line 12

def parse(body)
  case body
    when " " then nil
    else JSON.parse(body, :symbolize_names => true, :symbolize_keys => true)
  end
rescue JSON::ParserError
  raise CloudFoundry::Client::Exception::BadResponse, "Can't parse response into JSON:" + body
end