NSError code to detailed message

627 Views Asked by At

In my recent iOS APP I am trying to connect SSL server with past date via AFNetworking. I am getting the error "The operation couldn't be completed. (NSURLErrorDomain error -1012)". I searched apple doc and found this error mean "NSURLErrorUserCancelledAuthentication" I need to show a more detailed error message on place of this High level message (NSURLErrorDomain error -1012). How can I convert this error code to more details string message. Should I need to do this my self (check error code and then show message accordingly) or Apple provide any other good way to show this message or is there any open source category or class available for the same. Already checked

2

There are 2 best solutions below

0
On

Earlier I was interested in similar thing. But could not find anything useful. I think you have to do it yourself. There is not standard mapping from Error code to detail text.

You have to write a function yourself which may return text details from an error code.

0
On

The NSError instance itself provides the most detailed messages about an error, through methods such as localizedDescription.

You've hit up against a bit of a special case though, in NSURLErrorUserCancelledAuthentication. It should only be generated in response to your code cancelling an authentication challenge. i.e. by calling completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil) or [challenge.sender cancelAuthenticationChallenge:challenge].

The framework figures that if a challenge has been cancelled, it's because the user asked to (and so there's no further UI to display), or your code chose to, and should display its own specific error info to the user.

Is there a bit of your code that is performing such a cancellation? Can you give us a bit more detail?