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 @@
clientScripts: [],
faultTolerant: true,
logLevel: "error",
httpStatusHandlers: {},
onDie: null,
onError: null,
onLoadError: null,
......@@ -1664,8 +1665,11 @@
casper.loadInProgress = false;
};
page.onResourceReceived = function(resource) {
if (resource.url === casper.requestUrl) {
if (resource.url === casper.requestUrl && resource.stage === "start") {
casper.currentHTTPStatus = resource.status;
if (isType(casper.options.httpStatusHandlers, "object") && resource.status in casper.options.httpStatusHandlers) {
casper.options.httpStatusHandlers[resource.status](casper, resource);
}
casper.currentUrl = resource.url;
}
};
......
phantom.injectJs('casper.js');
var links = [];
var casper = new phantom.Casper({
httpStatusHandlers: {
404: function(self, resource) {
self.echo('Resource at ' + resource.url + ' not found (404)');
}
},
verbose: true
});
casper.start('http://www.google.com/plop', function(self) {
self.echo('Done.').exit();
});
casper.run();
\ No newline at end of file