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.)'
Showing
2 changed files
with
21 additions
and
1 deletions
... | @@ -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 | }; | ... | ... |
samples/statushandlers.js
0 → 100644
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 |
-
Please register or sign in to post a comment