Commit 44c240ff 44c240ff00252e436246984152db0647d7ac087e by Nicolas Perriault

better handling of ajax retrieval failures (more informative)

1 parent 913be452
Showing 1 changed file with 10 additions and 1 deletions
......@@ -818,17 +818,26 @@
};
/**
* Retrieves string contents from a binary file behind an url.
* Retrieves string contents from a binary file behind an url. Silently
* fails but log errors.
*
* @param String url
* @return string
*/
this.getBinary = function(url) {
try {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.overrideMimeType("text/plain; charset=x-user-defined");
xhr.send(null);
return xhr.responseText;
} catch (e) {
if (e.name === "NETWORK_ERR" && e.code === 101) {
console.log('unfortunately, casperjs cannot make cross domain ajax requests');
}
console.log('error while fetching ' + url + ': ' + e);
return "";
}
};
/**
......