I'm using AFNetworking
. I've subclassed AFURLConnectionOperation
and am using setWillSendRequestForAuthenticationChallengeBlock
to override the handling of AuthenticationChallenge
. I'm setting the Authorization header in every request and the server returns 401 for wrong credentials.
My use case is, if I send more than a certain number of requests with wrong credentials, the account will get locked out. I'm trying to prevent that by cancelling the authentication challenge so that only one request is sent.
[challenge.sender cancelAuthenticationChallenge:challenge];
But when I do this, the connection operation is failing with error -1012 (NSURLErrorDomain kCFURLErrorUserCancelledAuthentication) and thus I lose the actual error code 401.
Is there a way to cancel the challenge without failing the connection?