class Databasedotcom::SalesForceError

An exception raised when any non successful request is made to Force.com.

Attributes

error_code[RW]

the errorCode from the server response body

response[RW]

the Net::HTTPResponse from the API call

Public Class Methods

new(response) click to toggle source
Calls superclass method
# File lib/databasedotcom/sales_force_error.rb, line 9
def initialize(response)
  self.response = response
  parsed_body = JSON.parse(response.body) rescue nil
  if parsed_body
    if parsed_body.is_a?(Array)
      if parsed_body[0]["errors"]
        message = parsed_body[0]["errors"][0]["message"]
        self.error_code = parsed_body[0]["errors"][0]["statusCode"]
      else
        message = parsed_body[0]["message"]
        self.error_code = parsed_body[0]["errorCode"]
      end
    else
      message = parsed_body["error_description"]
      self.error_code = parsed_body["error"]
    end
  else
    message = response.body
  end
  super(message)
end