sergey.syrotynin sergey.syrotynin - 3 months ago 18
HTTP Question

What is the best way to handle https error codes in iOS?

My goal is to show a source of error to user. For now I'm using

NSError localizedDescription
string and check if network is reachable.
But sometimes 403, 500... codes appear. I should not display any technical code to user, all error codes must be translated in meaningful english. As I see it, one of the possible solutions is to manually check status code of most popular http errors and provide messages for them.
So my question is, what is the best approach to display http errors to user?


You can display localized description to user. Localized description's core goal is readability so you should use it!

Localized Description :

A string containing the localized description of the error. (read-only) The object in the user info dictionary for the key NSLocalizedDescriptionKey. If the user info dictionary doesn’t contain a value for NSLocalizedDescriptionKey, a default string is constructed from the domain and code.

So, if there is no value for NSLocalizedDescriptionKey is found then it will return string from domain and code!

So, in this kind of case you can manage your own custom messages! You can set some common standard message also like - server is not responding or unable to complete request etc!!!