fix edge case where res.respond would not work, misc comments

This commit is contained in:
Matteo Pagliazzi
2016-01-13 18:35:29 +01:00
parent 7a8321ec36
commit 6088b6da42
4 changed files with 6 additions and 4 deletions

View File

@@ -146,6 +146,7 @@ api.getChallenge = {
let challenge = await Challenge.findOne({_id: challengeId}).exec(); // TODO populate
// If the challenge does not exist, or if it exists but user is not a member, not the leader and not an admin -> throw error
// TODO support challenges in groups I'm a member of
if (!challenge || (user.challenges.indexOf(challengeId) === -1 && challenge.leader !== user._id && !user.contributor.admin)) { // eslint-disable-line no-extra-parens
throw new NotFound(res.t('challengeNotFound'));
}

View File

@@ -100,13 +100,13 @@ api.getGroups = {
type: 'guild',
privacy: 'private',
_id: {$in: user.guilds},
}).select(groupFields).sort(sort).exec()); // TODO isMember
}).select(groupFields).sort(sort).exec());
break;
case 'publicGuilds':
queries.push(Group.find({
type: 'guild',
privacy: 'public',
}).select(groupFields).sort(sort).exec()); // TODO use lean? isMember
}).select(groupFields).sort(sort).exec()); // TODO use lean?
break;
case 'tavern':
queries.push(Group.getGroup(user, 'habitrpg', groupFields));

View File

@@ -74,5 +74,7 @@ export default function errorHandler (err, req, res, next) { // eslint-disable-l
if (responseErr.errors) jsonRes.errors = responseErr.errors;
return res.respond(responseErr.httpCode, jsonRes);
// In some occasions like when invalid JSON is supplied `res.respond` might be not yet avalaible,
// in this case we use the standard res.status(...).json(...)
return res.respond ? res.respond(responseErr.httpCode, jsonRes) : res.status(responseErr.httpCode).json(jsonRes);
}

View File

@@ -146,7 +146,6 @@ schema.statics.getGroup = function getGroup (user, groupId, fields, optionalMemb
// TODO purge chat flags info? in tojson?
};
// TODO move to its own model
export function chatDefaults (msg, user) {
let message = {
id: shared.uuid(),