Exception: Databasedotcom::SalesForceError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/databasedotcom/sales_force_error.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SalesForceError

Returns a new instance of SalesForceError.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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)
      message = parsed_body[0]["message"]
      self.error_code = parsed_body[0]["errorCode"]
    else
      message = parsed_body["error_description"]
      self.error_code = parsed_body["error"]
    end
  else
    message = response.body
  end
  super(message)
end

Instance Attribute Details

#error_codeObject

the errorCode from the server response body



7
8
9
# File 'lib/databasedotcom/sales_force_error.rb', line 7

def error_code
  @error_code
end

#responseObject

the Net::HTTPResponse from the API call



5
6
7
# File 'lib/databasedotcom/sales_force_error.rb', line 5

def response
  @response
end