Dont call 'next' callback twice, include error message if zip don't exit normally

This commit is contained in:
Daniel García Aubert 2017-04-10 18:26:23 +02:00 committed by Mario de Frutos
parent 4b98b7056a
commit 884d3aea0a

View File

@ -59,15 +59,24 @@ ShpFormat.prototype.toSHP = function (options, callback) {
var child = spawn(zip, ['-qrj', zipfile, outdirpath ]);
child.on('exit', function(code) {
//console.log("Zip complete, zip return code was " + code);
if (code) {
next(new Error("Zip command return code " + code));
//res.statusCode = 500;
}
next(null);
var stderrData = [];
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
stderrData.push(data);
});
child.on('exit', function(code) {
if (code !== 0) {
var errMessage = 'Zip command return code ' + code;
if (stderrData.length) {
errMessage += ', Error: ' + stderrData.join('\n');
}
return next(new Error(errMessage));
}
return next();
});
},
function cleanupDir(topError) {