Commit 8723ef39 8723ef39e7ac89bdb4009cf20168ab26f97d6281 by Nicolas Perriault

closes #12 - added a new Casper 'httpStatusHandlers option object which can cont…

…ain dedicated HTTP status code handlers, one per code (404, 500, 403, etc.)'
1 parent 9e3916fc
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
44 clientScripts: [], 44 clientScripts: [],
45 faultTolerant: true, 45 faultTolerant: true,
46 logLevel: "error", 46 logLevel: "error",
47 httpStatusHandlers: {},
47 onDie: null, 48 onDie: null,
48 onError: null, 49 onError: null,
49 onLoadError: null, 50 onLoadError: null,
...@@ -1664,8 +1665,11 @@ ...@@ -1664,8 +1665,11 @@
1664 casper.loadInProgress = false; 1665 casper.loadInProgress = false;
1665 }; 1666 };
1666 page.onResourceReceived = function(resource) { 1667 page.onResourceReceived = function(resource) {
1667 if (resource.url === casper.requestUrl) { 1668 if (resource.url === casper.requestUrl && resource.stage === "start") {
1668 casper.currentHTTPStatus = resource.status; 1669 casper.currentHTTPStatus = resource.status;
1670 if (isType(casper.options.httpStatusHandlers, "object") && resource.status in casper.options.httpStatusHandlers) {
1671 casper.options.httpStatusHandlers[resource.status](casper, resource);
1672 }
1669 casper.currentUrl = resource.url; 1673 casper.currentUrl = resource.url;
1670 } 1674 }
1671 }; 1675 };
......
1 phantom.injectJs('casper.js');
2
3 var links = [];
4 var casper = new phantom.Casper({
5 httpStatusHandlers: {
6 404: function(self, resource) {
7 self.echo('Resource at ' + resource.url + ' not found (404)');
8 }
9 },
10 verbose: true
11 });
12
13 casper.start('http://www.google.com/plop', function(self) {
14 self.echo('Done.').exit();
15 });
16 casper.run();
...\ No newline at end of file ...\ No newline at end of file