Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

HTTPClient Error Handling

Hi there
I have the following httpclient code:

pastie

The first commented loadRSSFeed call is successful because the address is on the local LAN. The second one that loads http://www.google.com however fails after some time. I think there is some kind of proxy issue here but I'm not sure how to check on the error result. What properties does the "e" object in my xhr.onerror = function(e) have so that I can troubleshoot this? On a sidenote the Android emulator can access http://www.google.com through the native browser. This I got working by setting the proxy address port username etc on the phone itself.

Please help.<br>
Many thanks.<br>
-De Wet<br>

— asked July 27th 2010 by De Wet Steynberg
  • android
0 Comments

2 Answers

  • Accepted Answer

    make on_err

    function(e) {
    
        alert(e.error);
    
    }
    
    — answered July 27th 2010 by Dan Tamas
    permalink
    0 Comments
  • I do this:

    var r_ajax =  function(url,on_ok, on_err, method) {
        var method = !!method ? method : 'POST';
        var xhr = Titanium.Network.createHTTPClient();
    
        xhr.onload = on_ok;
        xhr.onerror = on_err;
    
        xhr.open(method,url);
    
        return {
            xhr:xhr,
            send:function(data) { xhr.send(data); }
        };
    };
    

    I set onload first , then open

    ( this is tested on iPhone )

    — answered July 27th 2010 by Dan Tamas
    permalink
    1 Comment
    • That's pretty neat, think I'll use it, but it still doesn't quite answer the question.

      I want to know what gets passed to the on_err.
      If you look at my pastie again you will see there's an "e" object there. I want to know what kind of object is it? if I alert it I just get "object". And typeof(e) also just returns "object". Trying to alert e.message just returns undefined. Now if the onerror gets called, we know something went wrong, but what?? network connectivity? proxy authentication? malformed url?? Thats the real question since I think it will help me narrow down why it's not working.

      PS: Using your method, very nice, on my side it still only works for local addresses though…

      — commented July 27th 2010 by De Wet Steynberg
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.