Skip to content

Commit

Permalink
Add a Mongo err handler here
Browse files Browse the repository at this point in the history
* Some STYLEGUIDE.md conformance in this function

Applies to OpenUserJS#430
  • Loading branch information
Martii committed Apr 19, 2017
1 parent 2fb68cd commit f253cf9
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,32 +299,48 @@ exports.getSource = function (aReq, aCallback) {
var isLib = aReq.params.isLib;

Script.findOne({
installName: caseSensitive(installNameBase +
(isLib ? '.js' : '.user.js'))
installName: caseSensitive(installNameBase + (isLib ? '.js' : '.user.js'))

}, function (aErr, aScript) {
var s3Object = null;
var s3 = new AWS.S3();

// WARNING: Partial error handling at this stage
if (aErr) {
if (isDbg) {
console.error(
'Document lookup failure for',
installNameBase + (isLib ? '.js' : '.user.js'),
aErr.message
);
}

if (!aScript) {
aCallback(null);
return;
}

if (!aScript) {
if (isDbg) {
console.warn('no script found yet' );
console.warn(
'Document not found for', installNameBase + (isLib ? '.js' : '.user.js')
);
}
aCallback(null);
return;
}

s3Object = s3.getObject({ Bucket: bucketName, Key: installNameBase + (isLib ? '.js' : '.user.js') }).createReadStream().
on('error', function () {
// TODO: #486
if (isDbg) {
console.error('S3 Key Not Found ' + installNameBase + (isLib ? '.js' : '.user.js'));
}
s3Object = s3.getObject({
Bucket: bucketName,
Key: installNameBase + (isLib ? '.js' : '.user.js')

aCallback(null);
return;
});
}).createReadStream().on('error', function () {
// TODO: #486
if (isDbg) {
console.error('S3 key not found for', installNameBase + (isLib ? '.js' : '.user.js'));
}

aCallback(null);
return;
});

// Get the script
aCallback(aScript, s3Object);
Expand Down

0 comments on commit f253cf9

Please sign in to comment.