diff --git a/routes/api/account/index.js b/routes/api/account/index.js index 4eab8b920..ee10636bf 100644 --- a/routes/api/account/index.js +++ b/routes/api/account/index.js @@ -102,15 +102,13 @@ router.put('/password/reset', (req, res, next) => { UsersService .verifyPasswordResetToken(token) - .then(user => { + .then((user) => { return UsersService.changePassword(user.id, password); }) .then(() => { res.status(204).end(); }) - .catch(error => { - console.error(error); - + .catch(() => { next(authorization.ErrNotAuthorized); }); }); @@ -121,12 +119,8 @@ router.put('/username', authorization.needed(), (req, res, next) => { .then(() => { res.status(204).end(); }) - .catch(error => { - if (error.code === 11000) { - next(errors.ErrUsernameTaken); - } else { - next(error); - } + .catch((err) => { + next(err); }); }); diff --git a/routes/api/assets/index.js b/routes/api/assets/index.js index 0b6762de8..3bb3ef778 100644 --- a/routes/api/assets/index.js +++ b/routes/api/assets/index.js @@ -79,7 +79,8 @@ router.get('/:asset_id', (req, res, next) => { .findById(req.params.asset_id) .then((asset) => { if (!asset) { - return res.status(404).end(); + res.status(404).end(); + return; } res.json(asset); @@ -97,15 +98,17 @@ router.post('/:asset_id/scrape', (req, res, next) => { .findById(req.params.asset_id) .then((asset) => { if (!asset) { - return res.status(404).end(); + res.status(404).end(); + return; } - return scraper.create(asset); - }) - .then((job) => { + return scraper + .create(asset) + .then((job) => { - // Send the job back for monitoring. - res.status(201).json(job); + // Send the job back for monitoring. + res.status(201).json(job); + }); }) .catch((err) => { next(err); @@ -117,8 +120,12 @@ router.put('/:asset_id/settings', (req, res, next) => { // Override the settings for the asset. AssetsService .overrideSettings(req.params.asset_id, req.body) - .then(() => res.status(204).end()) - .catch((err) => next(err)); + .then(() => { + res.status(204).end(); + }) + .catch((err) => { + next(err); + }); }); router.put('/:asset_id/status', (req, res, next) => { diff --git a/routes/api/settings/index.js b/routes/api/settings/index.js index f1a5fe9f7..5c4b03568 100644 --- a/routes/api/settings/index.js +++ b/routes/api/settings/index.js @@ -5,7 +5,8 @@ const router = express.Router(); router.get('/', (req, res, next) => { SettingsService - .retrieve().then((settings) => { + .retrieve() + .then((settings) => { res.json(settings); }) .catch((err) => { diff --git a/routes/api/setup/index.js b/routes/api/setup/index.js index e325769cd..dfddc64d9 100644 --- a/routes/api/setup/index.js +++ b/routes/api/setup/index.js @@ -43,7 +43,7 @@ router.post('/', (req, res, next) => { res.status(204).end(); }) .catch((err) => { - return next(err); + next(err); }); }); diff --git a/routes/api/users/index.js b/routes/api/users/index.js index df7369bb3..2af6bc2ee 100644 --- a/routes/api/users/index.js +++ b/routes/api/users/index.js @@ -152,7 +152,7 @@ router.post('/:user_id/actions', authorization.needed(), (req, res, next) => { .then((action) => { // Set the user status to "pending" for review by moderators - if (action_type.slice(0, 4) === 'FLAG') { + if (action_type === 'FLAG') { return UsersService.setStatus(req.params.user_id, 'PENDING') .then(() => action); } else { diff --git a/services/users.js b/services/users.js index b09a7d399..cf3a0063d 100644 --- a/services/users.js +++ b/services/users.js @@ -686,9 +686,20 @@ module.exports = class UsersService { canEditName: false, status: 'PENDING' } - }).then((result) => { - return result.nModified > 0 ? result : - Promise.reject(errors.ErrPermissionUpdateUsername); + }) + .then((result) => { + if (result.nModified <= 0) { + return Promise.reject(errors.ErrPermissionUpdateUsername); + } + + return result; + }) + .catch((err) => { + if (err.code === 11000) { + throw errors.ErrUsernameTaken; + } + + throw err; }); } };