Commit 44c240ff 44c240ff00252e436246984152db0647d7ac087e by Nicolas Perriault

better handling of ajax retrieval failures (more informative)

1 parent 913be452
Showing 1 changed file with 15 additions and 6 deletions
...@@ -818,17 +818,26 @@ ...@@ -818,17 +818,26 @@
818 }; 818 };
819 819
820 /** 820 /**
821 * Retrieves string contents from a binary file behind an url. 821 * Retrieves string contents from a binary file behind an url. Silently
822 * fails but log errors.
822 * 823 *
823 * @param String url 824 * @param String url
824 * @return string 825 * @return string
825 */ 826 */
826 this.getBinary = function(url) { 827 this.getBinary = function(url) {
827 var xhr = new XMLHttpRequest(); 828 try {
828 xhr.open("GET", url, false); 829 var xhr = new XMLHttpRequest();
829 xhr.overrideMimeType("text/plain; charset=x-user-defined"); 830 xhr.open("GET", url, false);
830 xhr.send(null); 831 xhr.overrideMimeType("text/plain; charset=x-user-defined");
831 return xhr.responseText; 832 xhr.send(null);
833 return xhr.responseText;
834 } catch (e) {
835 if (e.name === "NETWORK_ERR" && e.code === 101) {
836 console.log('unfortunately, casperjs cannot make cross domain ajax requests');
837 }
838 console.log('error while fetching ' + url + ': ' + e);
839 return "";
840 }
832 }; 841 };
833 842
834 /** 843 /**
......