Skip to content

Node.js based forum software built for the modern web

error check

barisusaklia6e498bb5d6b
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) {