From cfa07f44492495601151f56ecbdb1aafe5fc59ce Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 15 Jan 2016 12:11:11 +0000 Subject: [PATCH] fix error handling in standalone --- plugins/c9.vfs.standalone/standalone.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/c9.vfs.standalone/standalone.js b/plugins/c9.vfs.standalone/standalone.js index cd2019e7..ea70fea4 100644 --- a/plugins/c9.vfs.standalone/standalone.js +++ b/plugins/c9.vfs.standalone/standalone.js @@ -168,6 +168,8 @@ function plugin(options, imports, register) { }); var path = resolve(__dirname + "/../../build/output/latest.tar.gz"); fs.readlink(path, function(err, target) { + if (err) return next(err); + res.end((target || "").split(".")[0]); }); }); @@ -176,9 +178,19 @@ function plugin(options, imports, register) { var filename = req.params.path; var path = resolve(__dirname + "/../../build/output/" + filename); - res.writeHead(200, {"Content-Type": "application/octet-stream"}); var stream = fs.createReadStream(path); - stream.pipe(res); + stream.on("error", function(err) { + next(err); + }); + stream.on("data", function(data) { + if (!res.headersSent) + res.writeHead(200, {"Content-Type": "application/octet-stream"}); + + res.write(data); + }); + stream.on("end", function(data) { + res.end(); + }); }); api.get("/configs/require_config.js", function(req, res, next) {