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 ]); var child = spawn(zip, ['-qrj', zipfile, outdirpath ]);
child.on('exit', function(code) { var stderrData = [];
//console.log("Zip complete, zip return code was " + code); child.stderr.setEncoding('utf8');
if (code) { child.stderr.on('data', function (data) {
next(new Error("Zip command return code " + code)); stderrData.push(data);
//res.statusCode = 500;
}
next(null);
}); });
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) { function cleanupDir(topError) {