title: AFNetworking with Unreliable wifi - Detecting / Retrying connections when they timeout
body: <p>I'm using AFNetworking in my app to connect / download data from a web service. This app is deployed via Enterprise deployment to users at various locations. At one of the locations where people use our app, the wifi network seems to randomly go down / come back up in a few seconds. In these cases, the requirement was to retry a request thrice before giving up and failing. I've got the retry part of it working fine, but have some problems detecting a network failure. Some code:</p>
  
  <pre><code>AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
  [operation setCompletionBlockWithSuccess:
       ^(AFHTTPRequestOperation *operation, id responseObject) {
           [self parseResponse:operation.responseString];
       }
  
       failure:^(AFHTTPRequestOperation *operation, NSError *error) {
           [self messageFailureWithCode:error.code
                                 reason:[NSString stringWithFormat:@"%@", error]];
       }
   ];
  </code></pre>
  
  <p>The error code I'm retrying on is <code>NSURLErrorTimedOut</code>. But I just got another log file which indicated a failure with the following error: <code>-1003 "A server with the specified hostname could not be found."</code></p>
  
  <p>I could add this code to my list too, but I wanted to be sure that I'm capturing all the errors and not just handling them as they appear. I was looking through the NSURLError.h file and found the following error codes that vaguely look like they could be caused by a network failure. </p>
  
  <p>Can someone help me figuring out under what conditions each error is triggered and if I'm missing any error codes? The list is below:</p>
  
  <pre><code>NSURLErrorCannotFindHost
  NSURLErrorTimedOut
  NSURLErrorCannotConnectToHost
  NSURLErrorNetworkConnectionLost
  NSURLErrorDNSLookupFailed
  NSURLErrorResourceUnavailable
  NSURLErrorNotConnectedToInternet
  </code></pre>
  
  <p>Thanks, <br />
  Teja.</p>