Skip to content

Commit 6efcd92

Browse files
authored
Add a Mongo err handler here (OpenUserJS#1085)
* Some STYLEGUIDE.md conformance in this function Applies to OpenUserJS#430 Auto-merge
1 parent 2fb68cd commit 6efcd92

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

controllers/scriptStorage.js

+30-14
Original file line numberDiff line numberDiff line change
@@ -299,32 +299,48 @@ exports.getSource = function (aReq, aCallback) {
299299
var isLib = aReq.params.isLib;
300300

301301
Script.findOne({
302-
installName: caseSensitive(installNameBase +
303-
(isLib ? '.js' : '.user.js'))
302+
installName: caseSensitive(installNameBase + (isLib ? '.js' : '.user.js'))
303+
304304
}, function (aErr, aScript) {
305305
var s3Object = null;
306306
var s3 = new AWS.S3();
307307

308-
// WARNING: Partial error handling at this stage
308+
if (aErr) {
309+
if (isDbg) {
310+
console.error(
311+
'Document lookup failure for',
312+
installNameBase + (isLib ? '.js' : '.user.js'),
313+
aErr.message
314+
);
315+
}
309316

310-
if (!aScript) {
311317
aCallback(null);
318+
return;
319+
}
320+
321+
if (!aScript) {
312322
if (isDbg) {
313-
console.warn('no script found yet' );
323+
console.warn(
324+
'Document not found for', installNameBase + (isLib ? '.js' : '.user.js')
325+
);
314326
}
327+
aCallback(null);
315328
return;
316329
}
317330

318-
s3Object = s3.getObject({ Bucket: bucketName, Key: installNameBase + (isLib ? '.js' : '.user.js') }).createReadStream().
319-
on('error', function () {
320-
// TODO: #486
321-
if (isDbg) {
322-
console.error('S3 Key Not Found ' + installNameBase + (isLib ? '.js' : '.user.js'));
323-
}
331+
s3Object = s3.getObject({
332+
Bucket: bucketName,
333+
Key: installNameBase + (isLib ? '.js' : '.user.js')
324334

325-
aCallback(null);
326-
return;
327-
});
335+
}).createReadStream().on('error', function () {
336+
// TODO: #486
337+
if (isDbg) {
338+
console.error('S3 key not found for', installNameBase + (isLib ? '.js' : '.user.js'));
339+
}
340+
341+
aCallback(null);
342+
return;
343+
});
328344

329345
// Get the script
330346
aCallback(aScript, s3Object);

0 commit comments

Comments
 (0)