MadMaxAPP
MadMaxAPP

Reputation: 1075

RestKit how to handle Authentication Failure

I'm unsingf RestKit in my iPad Project pulling some JSON Data from Server. The iOS app needs to authenticate via Basic HTTP Authentication.

If i enter wrong credentials, i can see on the console (Simulator):

W restkit.network:RKResponse.m:157 Failed authentication challenge after 1 failures

How can i catch this situation? I found nothing in RestKit documentation (and i'm sure there must be something).

Upvotes: 0

Views: 1407

Answers (2)

clopez
clopez

Reputation: 4372

Check the restkit response, I think you can check that using:

- (void) objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader{

    RKResponse *response = [objectLoader response];
    int statusCode = [response statusCode];

    if (![response isOK] || statusCode > 299) {

        id parsedResponse = [response parsedBody:NULL];
        if ([parsedResponse isKindOfClass:[NSDictionary class]]) {
            //check for the specific error here!!
        }

    }

}

Upvotes: 0

mja
mja

Reputation: 5066

Did you tried to implement the appropriate error handler in you RKObjectLoaderDelegate?

eg.

- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error 
{
    RKLogError(@"Hit error: %@", error);
}

You should get an error with Error Domain=NSURLErrorDomain Code=-1012 or similar.

Upvotes: 1

Related Questions