lib/citygrid/citygrid_exceptions.rb in citygrid_api-0.0.19 vs lib/citygrid/citygrid_exceptions.rb in citygrid_api-0.0.20

- old
+ new

@@ -1,15 +1,16 @@ module CityGridExceptions # Define parent error classes # All errors thrown in the API should extend APIError - Level 1 class APIError < StandardError - attr_accessor :request, :response + attr_accessor :request, :response, :curl - def initialize request, response, msg = "An API error occurred" + def initialize request, response, msg = "An API error occurred", curl=nil @request = request @response = response + @curl = curl super msg end end # Level 2 - These represent three different error scenarios: @@ -17,14 +18,15 @@ # 2. The API call/parameters were malformed # 3. The request was fine but their was an error API side class ResponseParseError < APIError attr_accessor :server_msg, :description, :raw_response - def initialize request, response, msg = nil + def initialize request, response, msg = nil, curl=nil self.raw_response = response # parse Tomcat error report - if response.match /<title>Apache Tomcat.* - Error report<\/title>/ + 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" @@ -148,12 +150,12 @@ #400 => RequestError, @possible_errors = { 0 => ResponseError, nil => ResponseParseError, "" => ResponseParseError, 400 => RequestError, 401 => AuthenticationError, 403 => RequestError, 405 => RequestError, 406 => HeaderError, - 409 => RequestError, 410 => RequestError, 415 => RequestError, 413 => RequestError, 414 => RequestError, - 424 => AuthTokenInvalidError, 500 => ResponseError, "CONTENT_API_ERROR" => ContentApiError, "SYSTEM_ERROR_TRY_AGAIN" => SystemErrorTryAgainError, + 409 => RequestError, 410 => RequestError, 415 => RequestError, 413 => RequestError, 414 => RequestError, + 500 => ResponseError, "CONTENT_API_ERROR" => ContentApiError, "SYSTEM_ERROR_TRY_AGAIN" => SystemErrorTryAgainError, "SYSTEM_ERROR_UNKNOWN" => SystemErrorUnknownError, "BAD_REQUEST_TYPE" => BadRequestTypeError, "INVALID_REQUEST_BODY" => InvalidRequestBodyError, "HEADER_CONTENT_TYPE_IS_REQUIRED" => ContentTypeRequiredError, "HEADER_CONTENT_TYPE_INVALID" => ContentTypeInvalidError, "HEADER_ACCEPT_IS_REQUIRED" => AcceptRequiredError, "HEADER_ACCEPT_INVALID" => AcceptInvalidError, "AUTH_TOKEN_INVALID" => AuthTokenInvalidError, "AUTH_TOKEN_EXPIRED" => AuthTokenExpiredError, @@ -186,15 +188,6 @@ else return APIError end end - def CityGridExceptions.print_superclasses error_code - begin - raise appropriate_error[error_code] - rescue => ex - class_hierarchy = ex.class.ancestors - class_hierarchy.slice!(class_hierarchy.index(StandardError)..-1) - return class_hierarchy.reverse.join("::") - end - end end \ No newline at end of file