Exception: CityGridExceptions::ResponseParseError
- Defined in:
- lib/citygrid/citygrid_exceptions.rb
Overview
Level 2 - These represent three different error scenarios:
-
Response is totally not parsable to JSON
-
The API call/parameters were malformed
-
The request was fine but their was an error API side
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
-
#server_msg ⇒ Object
Returns the value of attribute server_msg.
Attributes inherited from APIError
Instance Method Summary collapse
-
#initialize(request, response, msg = nil, curl = nil) ⇒ ResponseParseError
constructor
A new instance of ResponseParseError.
Constructor Details
#initialize(request, response, msg = nil, curl = nil) ⇒ ResponseParseError
Returns a new instance of ResponseParseError.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/citygrid/citygrid_exceptions.rb', line 23 def initialize request, response, msg = nil, curl=nil self.raw_response = response # parse Tomcat error report Rails.logger.error response.body if defined?(Rails.logger) if response.body.include?("<title>Apache Tomcat.* - Error report<\/title>") response.scan(/<p><b>(message|description)<\/b> *<u>(.*?)<\/u><\/p>/).each do |match| case match[0] when "message" self.server_msg = match[1] when "description" self.description = match[1] end end error_body = response.match(/<body>(.*?)<\/body>/m)[1] msg = <<-EOS Unexpected response format. Expected response to be a hash, but was instead:\n#{error_body}\n EOS super request, response, msg, curl else msg = <<-EOS Unexpected response format. Expected response to be a hash, but was instead:\n#{response.parsed_response}\n EOS super request, response, msg, curl end end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
22 23 24 |
# File 'lib/citygrid/citygrid_exceptions.rb', line 22 def description @description end |
#raw_response ⇒ Object
Returns the value of attribute raw_response.
22 23 24 |
# File 'lib/citygrid/citygrid_exceptions.rb', line 22 def raw_response @raw_response end |
#server_msg ⇒ Object
Returns the value of attribute server_msg.
22 23 24 |
# File 'lib/citygrid/citygrid_exceptions.rb', line 22 def server_msg @server_msg end |