Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Add better error handling when calling rasterizer #68

Open
slorber opened this issue Dec 11, 2014 · 1 comment
Open

Add better error handling when calling rasterizer #68

slorber opened this issue Dec 11, 2014 · 1 comment

Comments

@slorber
Copy link

slorber commented Dec 11, 2014

When PhantomJS fails to download the web page (page.open), it actually returns a status code of 200 + a failure message in the body.

The PhantomJS service should rather return an error code 502 Bad Gateway. So that the screenshot serving service can display a better error message.

The page.open error message can be accessed by the page API: check http://newspaint.wordpress.com/2013/04/25/getting-to-the-bottom-of-why-a-phantomjs-page-load-fails/

slorber added a commit to slorber/screenshot-as-a-service that referenced this issue Dec 11, 2014
@slorber
Copy link
Author

slorber commented Dec 11, 2014

@fzaninotto notice I added a PR for this

I don't really know the original reasons why you did write the statusCode=200 directly because PhantomJS drop the connections. I don't know that behavior but tried to fix as best as I can so that it is easier to debug.

I've delayed a bit this "direct writing" with a useful comment:

  // This has been delayed a bit on purpose because once you write the http status code, 
  // you can't change it in case of error :(
  // So we only start writing after 500ms so that the page.open has a time window 
  // to eventually trigger an error with the appropriate status code
  window.setTimeout(function () {
    // must start the response now, or phantom closes the connection
    if ( pageOpenCallbackFired ) {
      response.statusCode = 200;
      response.write('');
    }
  },500);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant