From 73c681b98fc7dbfbfd3662cc48c181066757d3b6 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 17 Nov 2016 10:20:29 -0700 Subject: [PATCH 1/4] Added missing service function --- models/user.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/models/user.js b/models/user.js index 9446a949b..091bf62a0 100644 --- a/models/user.js +++ b/models/user.js @@ -443,3 +443,10 @@ UserService.availabilityCheck = (email) => { }); }; +/** + * Returns a count of the current users. + * @return {Promise} + */ +UserService.count = () => { + return UserModel.count(); +}; From 68c689f95d10eb5b71349c444139d18655614cd9 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 17 Nov 2016 10:26:51 -0700 Subject: [PATCH 2/4] Added missing dep --- package.json | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0aae50ed8..d7f04a921 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,13 @@ "config": { "pre-git": { "commit-msg": [], - "pre-commit": ["npm run lint", "npm test"], - "pre-push": ["npm test"], + "pre-commit": [ + "npm run lint", + "npm test" + ], + "pre-push": [ + "npm test" + ], "post-commit": [], "post-merge": [] } @@ -26,7 +31,12 @@ "type": "git", "url": "git+https://github.com/coralproject/talk.git" }, - "keywords": ["talk", "coral", "coralproject", "ask"], + "keywords": [ + "talk", + "coral", + "coralproject", + "ask" + ], "author": "", "license": "Apache-2.0", "bugs": { @@ -36,6 +46,7 @@ "dependencies": { "bcrypt": "^0.8.7", "body-parser": "^1.15.2", + "cli-table": "^0.3.1", "commander": "^2.9.0", "connect-redis": "^3.1.0", "debug": "^2.2.0", From e809c479e18d651f8715ee52e137c605529abfa4 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 17 Nov 2016 10:30:34 -0700 Subject: [PATCH 3/4] Added all method on user service --- bin/cli-users | 2 +- models/user.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/cli-users b/bin/cli-users index b27c41e14..54d7f2927 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -206,7 +206,7 @@ function listUsers() { const mongoose = require('../mongoose'); User - .find() + .all() .then((users) => { let table = new Table({ head: [ diff --git a/models/user.js b/models/user.js index 091bf62a0..a28ea3863 100644 --- a/models/user.js +++ b/models/user.js @@ -450,3 +450,11 @@ UserService.availabilityCheck = (email) => { UserService.count = () => { return UserModel.count(); }; + +/** + * Returns all the users. + * @return {Promise} + */ +UserService.all = () => { + return UserModel.find(); +}; From 598b4d8bb11d21dd06283c6593587894ca2e4f47 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 17 Nov 2016 10:36:07 -0700 Subject: [PATCH 4/4] Improved error handling to add logging --- app.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/app.js b/app.js index f5b39a074..6512680aa 100644 --- a/app.js +++ b/app.js @@ -89,37 +89,27 @@ app.use((req, res, next) => { // General error handler. Respond with the message and error if we have it while // returning a status code that makes sense. -if (app.get('env') === 'development') { - app.use('/api', (err, req, res, next) => { - res.status(err.status || 500); - res.json({ - message: err.message, - error: err - }); - }); - - app.use('/', (err, req, res, next) => { - res.status(err.status || 500); - res.render('error', { - message: err.message, - error: err - }); - }); -} - app.use('/api', (err, req, res, next) => { + if (err !== ErrNotFound) { + console.error(err); + } + res.status(err.status || 500); res.json({ message: err.message, - error: {} + error: app.get('env') === 'development' ? err : null }); }); app.use('/', (err, req, res, next) => { + if (err !== ErrNotFound) { + console.error(err); + } + res.status(err.status || 500); res.render('error', { message: err.message, - error: {} + error: app.get('env') === 'development' ? err : null }); });