Sha256: 76e967c52c3c76719abadbdb10305d7c1c15f8e13d4e3d2559e3cab1938a3185

Contents?: true

Size: 995 Bytes

Versions: 3

Compression:

Stored size: 995 Bytes

Contents

module Databasedotcom
  # An exception raised when any non successful request is made to Force.com.
  class SalesForceError < StandardError
    # the Net::HTTPResponse from the API call
    attr_accessor :response
    # the +errorCode+ from the server response body
    attr_accessor :error_code

    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
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
databasedotcom-1.3.5 lib/databasedotcom/sales_force_error.rb
databasedotcom-1.3.3 lib/databasedotcom/sales_force_error.rb
glg-databasedotcom-1.3.2.1 lib/databasedotcom/sales_force_error.rb