Exception: CityGridExceptions::ResponseParseError

Inherits:
APIError
  • Object
show all
Defined in:
lib/citygrid/citygrid_exceptions.rb

Overview

Level 2 - These represent three different error scenarios:

  1. Response is totally not parsable to JSON

  2. The API call/parameters were malformed

  3. The request was fine but their was an error API side

Instance Attribute Summary collapse

Attributes inherited from APIError

#curl, #request, #response

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



22
23
24
# File 'lib/citygrid/citygrid_exceptions.rb', line 22

def description
  @description
end

#raw_responseObject

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_msgObject

Returns the value of attribute server_msg.



22
23
24
# File 'lib/citygrid/citygrid_exceptions.rb', line 22

def server_msg
  @server_msg
end