Skip to content

Commit

Permalink
Adding exception handling for JSON.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmoo committed Mar 12, 2016
1 parent 7e3dd56 commit 49abf10
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions example/index.js
Expand Up @@ -48,9 +48,16 @@ var child_process = require('child_process'),
}
// check for newline ascii char 10
if (data.length && data[data.length-1] == 10) {
var output = JSON.parse(data.toString('UTF-8'));
data = null;
done(null, output);
try {
var output = JSON.parse(data.toString('UTF-8'));
data = null;
done(null, output);
} catch(err) {
done(JSON.stringify({
"error": err.toString('UTF-8'),
"payload": data.toString('UTF-8')
}));
}
};
});
})();
Expand Down

0 comments on commit 49abf10

Please sign in to comment.