Class: Hypernova::Response

Inherits:
Object
  • Object
show all
Includes:
PluginHelper
Defined in:
lib/hypernova/response.rb

Instance Method Summary collapse

Methods included from PluginHelper

#after_response, #get_view_data, #on_error, #on_success, #prepare_request, #send_request?, #will_send_request

Constructor Details

#initialize(request) ⇒ Response

Returns a new instance of Response.



7
8
9
# File 'lib/hypernova/response.rb', line 7

def initialize(request)
  @request = request
end

Instance Method Details

#parsed_bodyObject

Example parsed body with error:

"0" => {
  "html" => "<p>Error!</p>",
  "name" => "goodbye_galaxy.js",
  "meta" => {,
  "duration" => 100,
  "statusCode" => 500,
  "success" => false,
  "error" => {
    "name" => "TypeError",
    "message" => "Cannot read property 'forEach' of undefined",
    "stack" => [
      "TypeError: Cannot read property 'forEach' of undefined",
      "at TravelerLanding.componentWillMount",
      "at ReactCompositeComponentMixin.mountComponent",
    ],
  },
}

}



44
45
46
47
48
49
50
51
# File 'lib/hypernova/response.rb', line 44

def parsed_body
  response = parse_body
  # This enables backward compatibility with the old server response format.
  # In the new format, the response results are contained within a "results" key. The top level
  # hash contains a "success" and "error" which relates to the whole batch.
  response = response["results"] || response
  after_response(response, response)
end