Catch a parse error
Anyone knows how to catch a parse error from this.responseXML ?
Sometimes when fetching a xml input, it times out. Timeout message can appear inside the xml data and the parsing will bail out. I want to make attempts to fetch new data if the xml parsing fails.
8 Answers
-
if you want to catch the parse error then you can just get the response text and parse it in your own code.
wrap your
Ti.XML.parse(xhr.responseText)
in a try catch block -
did you find a solution for this error ? i have the same sometimes. thank you
-
Using a
try-catch statement
works well enough for me. Looks something like this:xhr.onload = function() { try { var doc = this.responseXML.documentElement; saveXML(doc); populateTableView(doc); // normal flow hideLoadingView(); } catch(e) { showLoadingViewRefresh(0); // code to be executed on error } };
-
Are you setting an error listener on HTTP client? Which platform are you testing on?
-
iPhone OS
Yes, but it does not catch this parser error:
Entity: line 43: parser error : Premature end of data in tag picture line 42
^[WARN] Error Domain=com.google.GDataXML Code=-1 "Operation could not be completed. (com.google.GDataXML error -1.)". in -[TiDOMDocumentProxy parseString:] (TiDOMDocumentProxy.m:45)
This is the code:
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function(e)
{
Ti.API.info("What ERROR -> " + e.error);
};xhr.onload = function()
{
var statusCode = this.status;
Titanium.API.log("info", " -> Status code: " + statusCode);var XMLtext = this.responseXML;
etc. etc.
-
Psst. Did you ever figure out what to do about this? I've got a really similar error, and I'm not sure what to do about it.
-
Timeouts should be catch on xhr's onerror. Try setting a timeout and see if that gets triggered.
-
No I have not found any solution to this. xhr's onerror does not catch parse error. When it times out I can't figure out the reason, only it timed out :-(