From e2bca6d705187e104c6c76ecc343c4f002f0c1a9 Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Dec 2014 13:34:57 -0700 Subject: [PATCH] Graceful failure when S3 *(fake or real)* doesn't have key * Directly related to #37. Stops net timeout when picking some other script that isn't present in fakeS3. Eventually when *aws-sdk* is updated this will be needed so it doesn't halt dev. Possibly applicable routine to #486 for inline live migration --- controllers/scriptStorage.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/controllers/scriptStorage.js b/controllers/scriptStorage.js index 1cbc36ed0..a99c0a573 100644 --- a/controllers/scriptStorage.js +++ b/controllers/scriptStorage.js @@ -50,14 +50,24 @@ exports.getSource = function (aReq, aCallback) { Script.findOne({ installName: caseInsensitive(installName) }, function (aErr, aScript) { + var s3Object = null; + if (!aScript) { return aCallback(null); } + s3Object = s3.getObject({ Bucket: bucketName, Key: installName }).createReadStream(). + on('error', function () { + if (isPro) { + console.error('S3 Key Not Found ' + installName); + } + + return aCallback(null); + }); + // Get the script - aCallback(aScript, s3.getObject({ Bucket: bucketName, Key: installName }) - .createReadStream()); - }); + aCallback(aScript, s3Object); + }); }; exports.sendScript = function (aReq, aRes, aNext) {