0
votes

I am using AfNetworking 1.0 into my app.I have created a singleton class of AFHTTP Client. So all the API's are place in the same class. I am getting a very wierd issue. For eg: Let say, i have requested for some data from server.But the internet connection has lost.

So the failure block get's called.

m getting the following error:

Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x797dcc70 {NSErrorFailingURLStringKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, _kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, NSLocalizedDescription=The Internet connection appears to be offline., _kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7aa367e0 "The Internet connection appears to be offline."}

But if i try to get the status code using following code:

NSLog(@"Status code %d",[operation.response statusCode]);

m getting Status Code as "0".

Can you please explain,why i am getting Status code as "0"? I have to handle the error,depends on HTTP Status Code.So what is the best way to get this done? (the same way which i am doing or is there any other way.)

1

1 Answers

0
votes

In this case you can't use the status code because there isn't one. The status code comes from the server and in this case the client has not been able to contact the server.

You should use the error domain and code to handle this case.