function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tschlosstschloss 

zkSforce (iPhone Simulator) - uncaught exception with wrong login credentials

Hi,

under OSX I had no problems with wrong login credentials - no program termination.

Now programming against iOS (iPhone Simulator 3.1.3) my App wants to do this

 

ZKSforceClient *client = [[ZKSforceClient alloc] init];

[client login:userid password:password];

 

and terminates with this log:

 

[Session started at 2010-12-02 09:48:57 +0100.]

2010-12-02 09:49:00.487 iOppBrwsr[9241:207] sendRequest - before THROW

2010-12-02 09:49:00.489 iOppBrwsr[9241:207] *** Terminating app due to uncaught exception 'INVALID_LOGIN', reason: 'INVALID_LOGIN: Invalid username, password, security token; or user locked out.'

2010-12-02 09:49:00.489 iOppBrwsr[9241:207] Stack: (

    30590043,

    2553984265,

    14504,

    30409,

    29873,

    11044,

    2819463,

    2857398,

    2845492,

    2827903,

    2855009,

    37481817,

    30374784,

    30370888,

    2821653,

    2858927,

    10708,

    10562

)

In BaseClient "sendRequest" it falls down to the very last error handling statement

@throw [ZKSoapException exceptionWithFaultCode:fc faultString:fm];


I admit that I am not very experienced with that, so probably it should be clear what to do. But honestly a little hint how I should handle this common situation would be great!
Any volunteers?

Thanks!
Thomas


Best Answer chosen by Admin (Salesforce Developers) 
tschlosstschloss

When looking on SF3 code I found code which probably is made for handling the exception in a try/catch pattern.

So I will learn and reuse from this now and maybe my question above will be solved.

 

 

 

- (ZKSforceClient *)performLogin:(ZKSoapException **)error {
[sforce release];
sforce = [[ZKSforceClient alloc] init];
[sforce setLoginProtocolAndHost:server];
if ([clientId length] > 0)
[sforce setClientId:clientId];
@try {
[sforce login:username password:password];
[[NSUserDefaults standardUserDefaults] setObject:server forKey:@"server"];
[[NSUserDefaults standardUserDefaults] setObject:username forKey:login_lastUsernameKey];
}
@catch (ZKSoapException *ex) {
if (error != nil) *error = ex;
return nil;
}
return sforce;
}

All Answers

tschlosstschloss

When looking on SF3 code I found code which probably is made for handling the exception in a try/catch pattern.

So I will learn and reuse from this now and maybe my question above will be solved.

 

 

 

- (ZKSforceClient *)performLogin:(ZKSoapException **)error {
[sforce release];
sforce = [[ZKSforceClient alloc] init];
[sforce setLoginProtocolAndHost:server];
if ([clientId length] > 0)
[sforce setClientId:clientId];
@try {
[sforce login:username password:password];
[[NSUserDefaults standardUserDefaults] setObject:server forKey:@"server"];
[[NSUserDefaults standardUserDefaults] setObject:username forKey:login_lastUsernameKey];
}
@catch (ZKSoapException *ex) {
if (error != nil) *error = ex;
return nil;
}
return sforce;
}
This was selected as the best answer
kyleRochekyleRoche

 

- (void)loginResult:(ZKLoginResult *)result error:(NSError *)error {
	if (result && !error) {
		// do stuff after login
	} else if (error) {
                // i use a shared singleton class to handle errors
		[appManager receivedErrorFromAPICall:error];
	}
}

 

That's what i'm using as a pattern. Hope that helps. I just put an alertview in the appManager class. That way I can centralize logging the error. I'm using that for all the API Calls and switching on context: for CRUD action selectors. 

 

SuperfellSuperfell

That's the pattern for the iOS toolkit (which forked zkSforce), not the original zkSforce library, so it'll depend on exactly which library is being used.