Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Time Out Error With AFNetworking

i use AFNetworking to retrieve data from my web service every thing work perfectly, but i want to detect the time out error. I used this code in the failure block of the request but i don't work

failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    if ([operation.response statusCode] == 408) {
      //time out error here
    }
}];

The code 408 is normaly for the time out error

like image 735
Mohamed Ghebaji Avatar asked Nov 09 '14 12:11

Mohamed Ghebaji


1 Answers

Since AFNetworking is build on top on NSULConnection/NSULRSession you can just NSURLErrorTimedOut to check if the error is a timeout error:

 failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    if (error.code == NSURLErrorTimedOut) {
      //time out error here
    }
}];

You where checking the HTTP status code, but since the connection timed out there is not statuscode.

like image 56
rckoenes Avatar answered Oct 28 '22 02:10

rckoenes