diff --git a/lib/cartodb/carto_data.js b/lib/cartodb/carto_data.js index 27d27168..86336b09 100644 --- a/lib/cartodb/carto_data.js +++ b/lib/cartodb/carto_data.js @@ -27,14 +27,20 @@ module.exports = function() { * Get the database name for this particular subdomain/username * * @param req - standard express req object. importantly contains host information - * @param callback + * @param callback - gets called with args(err, dbname) */ me.getDatabase = function(req, callback) { // strip subdomain from header host var username = req.headers.host.split('.')[0] var redisKey = _.template(this.user_key, {username: username}); - this.retrieve(this.user_metadata_db, redisKey, 'database_name', callback); + this.retrieve(this.user_metadata_db, redisKey, 'database_name', function(err, dbname) { + if ( err ) callback(err, null); + else if ( dbname === null ) { + callback(new Error("missing " + username + "'s dbname in redis (try CARTODB/script/restore_redis)"), null); + } + else callback(err, dbname); + }); }; @@ -50,7 +56,13 @@ module.exports = function() { var username = req.headers.host.split('.')[0]; var redisKey = _.template(this.user_key, {username: username}); - this.retrieve(this.user_metadata_db, redisKey, 'id', callback); + this.retrieve(this.user_metadata_db, redisKey, 'id', function(err, dbname) { + if ( err ) callback(err, null); + else if ( dbname === null ) { + callback(new Error("missing " + username + "'s dbuser in redis (try CARTODB/script/restore_redis)"), null); + } + else callback(err, dbname); + }); }; /** @@ -182,6 +194,8 @@ module.exports = function() { }; // Redis Hash lookup + // @param callback will be invoked with args (err, reply) + // note that reply is null when the key is missing me.retrieve = function(db, redisKey, hashKey, callback) { this.redisCmd(db,'HGET',[redisKey, hashKey], callback); };