fix(controller): Adjust next calls to throw errors instead inside promise

This commit is contained in:
Blade Barringer
2015-11-21 17:01:56 -06:00
parent d1839b816e
commit 867efd7078

View File

@@ -50,11 +50,9 @@ api.registerLocal = {
.exec() .exec()
.then((user) => { .then((user) => {
if (user) { if (user) {
if (email === user.auth.local.email) return next(new NotAuthorized(res.t('emailTaken'))); if (email === user.auth.local.email) throw new NotAuthorized(res.t('emailTaken'));
// Check that the lowercase username isn't already used // Check that the lowercase username isn't already used
if (lowerCaseUsername === user.auth.local.lowerCaseUsername) { if (lowerCaseUsername === user.auth.local.lowerCaseUsername) throw new NotAuthorized(res.t('usernameTaken'));
return next(new NotAuthorized(res.t('usernameTaken')));
}
} }
let salt = passwordUtils.makeSalt(); let salt = passwordUtils.makeSalt();
@@ -79,21 +77,19 @@ api.registerLocal = {
return newUser.save(); return newUser.save();
}) })
.then((savedUser) => { .then((savedUser) => {
if (savedUser) { res.status(201).json(savedUser);
res.status(201).json(savedUser);
// Clean previous email preferences // Clean previous email preferences
EmailUnsubscription EmailUnsubscription
.remove({email: savedUser.auth.local.email}) .remove({email: savedUser.auth.local.email})
.then(() => sendTxnEmail(savedUser, 'welcome')); .then(() => sendTxnEmail(savedUser, 'welcome'));
res.analytics.track('register', { res.analytics.track('register', {
category: 'acquisition', category: 'acquisition',
type: 'local', type: 'local',
gaLabel: 'local', gaLabel: 'local',
uuid: savedUser._id, uuid: savedUser._id,
}); });
}
}) })
.catch(next); .catch(next);
}, },