display HTTP errors and give up
[mkws-moved-to-github.git] / test / phantom / evaluate.js
index 27a2d71..8cc4c3e 100644 (file)
@@ -26,7 +26,7 @@ page.viewportSize = {
 
 // 0: silent, 1: some infos,  2: display console.log() output
 var debug = 2;
-if (system.env['DEBUG'] != 'undefined' && parseInt(system.env['DEBUG']) != NaN) {
+if (typeof system.env['DEBUG'] != 'undefined' && parseInt(system.env['DEBUG']) != NaN) {
     debug = system.env['DEBUG'];
     if (debug > 0) console.log("reset debug level to: " + debug);
 }
@@ -76,12 +76,18 @@ page.onAlert = function (msg) {
     console.log("Alert: " + msg);
 };
 
+// display HTTP errors
+page.onResourceError = function (resourceError) {
+    // console.log('phantomjs error code: ' + resourceError.errorCode);
+    console.log(resourceError.errorString);
+    phantom.exit(3);
+};
 
 page.open(url, function (status) {
     if (debug >= 1) console.log("fetch " + url + " with status: " + status);
 
     if (status != 'success') {
-        console.log("Failed to fetch page, give up");
+        console.log("Failed to fetch page, give up. Network error?");
         phantom.exit(1);
     }