Skip to content

Commit

Permalink
Implement better pattern and correct handling of faultcodes from SF.
Browse files Browse the repository at this point in the history
Further connection-related faults should just be extended with addition
when/then's + new SalesforceAdapter::Connection::Errors exception class, as
necessary.
  • Loading branch information
jpr5 committed Sep 9, 2011
1 parent 3578230 commit 4bbbee2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/dm-salesforce-adapter/connection.rb
Expand Up @@ -97,10 +97,10 @@ def login
begin
result = driver.login(:username => @username, :password => @password).result
rescue SOAP::FaultError => error
if error.faultcode.to_s =~ /INVALID_LOGIN/
raise LoginFailed, error.faultstring.to_s
else
raise error
case error.faultcode.text
when "sf:INVALID_LOGIN" then raise LoginFailed, error.faultstring.text
# ...
else raise error
end
end
driver.endpoint_url = result.serverUrl
Expand All @@ -127,17 +127,16 @@ def with_reconnection(&block)
yield
rescue SOAP::FaultError => error
retry_count ||= 0
if error.faultcode.to_s =~ /INVALID_SESSION_ID/

case error.faultcode.text
when "sf:INVALID_SESSION_ID" then
DataMapper.logger.debug "Got a invalid session id; reconnecting" if DataMapper.logger
@driver = nil
login
retry_count += 1
retry unless retry_count > 5
else
raise error
else raise error
end

raise SessionTimeout, "The Salesforce session could not be established"
end
end
end

0 comments on commit 4bbbee2

Please sign in to comment.