From a6e498bb5d6ba8ce667d55de85d97eb7f415b995 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 5 Nov 2014 16:48:09 -0500 Subject: [PATCH] error check --- src/groups.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/groups.js b/src/groups.js index 787e520b5d..d3ca167d6d 100644 --- a/src/groups.js +++ b/src/groups.js @@ -141,21 +141,24 @@ var async = require('async'), }; Groups.search = function(query, options, callback) { - if (query.length) { - db.getSetMembers('groups', function(err, groups) { - groups = groups.filter(function(groupName) { - return groupName.match(new RegExp(utils.escapeRegexChars(query), 'i')); - }); + if (!query) { + return callback(null, []); + } - async.map(groups, function(groupName, next) { - Groups.get(groupName, options, next); - }, function(err, groups) { - callback(err, internals.filterGroups(groups, options)); - }); + db.getSetMembers('groups', function(err, groups) { + if (err) { + return callback(err); + } + groups = groups.filter(function(groupName) { + return groupName.match(new RegExp(utils.escapeRegexChars(query), 'i')); }); - } else { - callback(null, []); - } + + async.map(groups, function(groupName, next) { + Groups.get(groupName, options, next); + }, function(err, groups) { + callback(err, internals.filterGroups(groups, options)); + }); + }); }; Groups.isMember = function(uid, groupName, callback) {