teampoltergeist/poltergeist — pull request #473 by dholdren (2014-04-03 16:09:23+00:00)
Title: Handle 'status: fail' responses from PhantomJS land instead of returning minimal HTML (i.e. "blank page")

## Problem:
### When there is a DNS issue, or the server is down, Poltergeist will return a body like this:
```html

```
In your capybara tests then, you will get `Unable to find field "foo" (Capybara::ElementNotFound)` when the actual problem is
a) your server name is unusable (i.e. what you set for Capybara.default_host or Capybara.app_host is not in /etc/hosts)
b) the server died somehow

## Solution:
### Detect a PhantomJS "fail" status.
When PhantomJS can't reach a server, it returns an actionable "status" value, and, oddly, a minimal HTML structure for page.body. Poltergeist should detect the status and raise an Error.
```js
var page = require('webpage').create();

var url = "http://nope";

page.onResourceReceived = function(resource) {
console.log('Url: ' + resource.url);
console.log('Code: ' + resource.status);
}

page.open(url, function(status) {
console.log('Status: ' + JSON.stringify(status));
console.log('Page: '+JSON.stringify(page));
phantom.exit();
});
```
```
Url: http://nope/
Code: null
Status: "fail"
Page: {"objectName":"WebPage","title":"","frameTitle":"","content":"

","frameContent":"

","url":"about:blank","frameUrl":"about:blank","loading":false,"loadingProgress":100,"canGoBack":false,"canGoForward":false,"plainText":"","framePlainText":"","libraryPath":"/Users/dholdren/tmp","offlineStoragePath":"/Users/dholdren/Library/Application Support/Ofi Labs/PhantomJS","offlineStorageQuota":5242880,"viewportSize":{"height":300,"width":400},"paperSize":{},"clipRect":{"height":0,"left":0,"top":0,"width":0},"scrollPosition":{"left":0,"top":0},"navigationLocked":false,"customHeaders":{},"zoomFactor":1,"cookies":[],"windowName":"","pages":[],"pagesWindowName":[],"ownsPages":true,"framesName":[],"frameName":"","framesCount":0,"focusedFrameName":""}
```
For a comparison of a "fail" vs. a "success" in PhantomJS:
https://gist.github.com/dholdren/9942454