Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ PDF.prototype.exec = function PdfExec (callback) {
// Ignore if code has a value of 0 since that means PhantomJS has executed and exited successfully.
// Also, as per your script and standards, having a code value of 1 means one can always assume that
// an error occured.
if (((typeof code !== 'undefined' && code !== null) && code !== 0) || err) {
if (((typeof code !== 'undefined' && code !== null) && code !== 0) || err || (code === 0 && !data)) {
var error = null

if (err) {
// Rudimentary checking if err is an instance of the Error class
error = err instanceof Error ? err : new Error(err)
} else if (code === 0 && !data) {
// This is to catch the edge case of having a exit code value of 0 but having no data (exit can be called before io pipes are closed)
error = new Error('html-pdf: Process exited successfully, but no data received')
} else {
// This is to catch the edge case of having a exit code value of 1 but having no error
error = new Error('html-pdf: Unknown Error')
Expand All @@ -150,7 +153,7 @@ PDF.prototype.exec = function PdfExec (callback) {

// An exit event is most likely an error because we didn't get any data at this point
child.on('close', respond)
child.on('exit', respond)
// child.on('exit', respond)

var config = JSON.stringify({html: this.html, options: this.options})
child.stdin.write(config + '\n', 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-pdf",
"version": "3.0.1",
"version": "3.0.2-kv",
"description": "HTML to PDF converter that uses phantomjs",
"engines": {
"node": ">=4.0.0"
Expand Down