Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

HTTPClient timeout retry pattern

$
0
0

I'm developing for iOS and I have a lot of issues with the timeout error, not depending from server side.

If I try immediately after a timeout it works well, both on simulator and physical devices, situation is worse if connected to a 3G network of course.

A workaround could be setting a shorter timeout and try a number of time, before assuming that the server is not answering. If I try this manually this works.

What could be an elegant pattern to force a second try and manage better the error?

Thanks

var xhr = Ti.Network.createHTTPClient();
xhr.url = url;
xhr.timeout = 4000;
 
xhr.onload = function() {
        Ti.App.fireEvent('app:actiononload', {data: this.responseText});
    }
Ti.App.addEventListener('app:actiononload', function(obj){
        // Success code
    });
 
xhr.onerror = function(e) {
    //Error code
    Ti.API.info(e);
}
 
 
 
xhr.open("GET", url);
xhr.send();

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>