Handling connectivity issues
As the only way to know if a network request might succeed is to actually attempt the request, we need to know how to properly handle the errors that might rise out of such an attempt.
If you recall our promisified XHR wrapper from Chapter 5, Communicating between Mobile and the Middle-Tier, you should know that it can throw several different kinds of errors (defined at the top of /www/js/app/lib/xhr.js
):
TimeoutError
: This error is thrown when the XHR times out. (Default is 30 seconds for our wrapper, but if the XHR's timeout isn't otherwise set, it will attempt to wait forever.)HTTPError
: This error is thrown when the XHR completes and receives a response other than200 OK
. This can indicate any number of problems, but it does not indicate a network connectivity issue.JSONError
: This error is thrown when the XHR completes, but the JSON response from the server cannot be parsed. Something is clearly wrong on the server, of course, but this does not indicate...