Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle Error Event? #103

Open
smyth64 opened this issue Aug 8, 2016 · 1 comment
Open

How to handle Error Event? #103

smyth64 opened this issue Aug 8, 2016 · 1 comment

Comments

@smyth64
Copy link

smyth64 commented Aug 8, 2016

Hey there!
How can I catch the error generated by phantom-render-stream?

I got this error sometimes, which causes my express server to crash.

Error: Render failed (1 tries) Request details: ...

Where do I have to make the try { } catch () { } ?

Thanks for this nice work!

@sorribas
Copy link
Owner

sorribas commented Aug 9, 2016

The error is emitted on the rendering string, so you have to add an error handler to it. Something like this.

var phantom = require('phantom-render-stream');
var render = phantom();

var stream = render('http://example.com/my-site');
stream.pipe(fs.createWriteStream('out.png'));
stream.on('error', function(err) {
  // handle error here
});

You can also use pump instead of pipe, which does error handling for you.

Additionally you can pass set the retries option to something higher so that phantom-render-stream tries more than once to do the rendering. Something like this.

var phantom = require('phantom-render-stream');
var render = phantom({retries: 5});

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

No branches or pull requests

2 participants