Small Cleanup

This commit is contained in:
2016-05-11 22:21:19 +05:30
parent b945f4ec43
commit 4932e5491e
+4 -6
View File
@@ -40,7 +40,7 @@ app.get( '/:package', function( req, res, next ){
if( !isExists ){ if( !isExists ){
if ( !ENABLE_NPM_FAILOVER ) { if ( !ENABLE_NPM_FAILOVER ) {
res._log.cacheHit = '!!!'; res._log.cacheHit = '!!!';
return Promise.reject( { status:404, message: {}}); return Promise.reject( { status: 404 });
} }
res._log.cacheHit = '---'; res._log.cacheHit = '---';
return fetchAndCacheMetadata( packageName, cacheFile ); return fetchAndCacheMetadata( packageName, cacheFile );
@@ -68,7 +68,7 @@ app.get( '/:package/-/:tarball', function( req, res, next ){
if( !isExists ){ if( !isExists ){
if ( !ENABLE_NPM_FAILOVER ) { if ( !ENABLE_NPM_FAILOVER ) {
res._log.cacheHit = '!!!'; res._log.cacheHit = '!!!';
return Promise.reject( { status: 404, message: {} }); return Promise.reject( { status: 404 });
} }
res._log.cacheHit = '---'; res._log.cacheHit = '---';
return fetchAndCacheTarball( packageName, version, packagePath ); return fetchAndCacheTarball( packageName, version, packagePath );
@@ -84,17 +84,15 @@ app.get( '/:package/-/:tarball', function( req, res, next ){
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
var err = new Error('Not Found'); next({ status: 404 });
err.status = 404;
next(err);
}); });
// error handlers // error handlers
app.use(function(err, req, res, next) { app.use(function(err, req, res, next) {
var message = err.message || err;
err.stack && console.log( err.stack ); err.stack && console.log( err.stack );
res.status(err.status || 500); res.status(err.status || 500);
var message = err.message || err;
// NPM registry returns empty objects for unknown packages // NPM registry returns empty objects for unknown packages
if( err.status == 404 ){ if( err.status == 404 ){
message = {}; message = {};