improved logging and error handling

This commit is contained in:
Steve Waterworth
2019-01-23 18:02:32 +00:00
parent fb09bf5410
commit d08e90c589
3 changed files with 102 additions and 23 deletions

View File

@@ -54,6 +54,7 @@ app.get('/health', (req, res) => {
// use REDIS INCR to track anonymous users
app.get('/uniqueid', (req, res) => {
req.log.error('Unique ID test');
// get number from Redis
redisClient.incr('anonymous-counter', (err, r) => {
if(!err) {
@@ -67,6 +68,25 @@ app.get('/uniqueid', (req, res) => {
});
});
// check user exists
app.get('/check/:id', (req, res) => {
if(mongoConnected) {
usersCollection.findOne({name: req.params.id}).then((user) => {
if(user) {
res.send('OK');
} else {
res.status(404).send('user not found');
}
}).catch((e) => {
req.log.error(e);
res.send(500).send(e);
});
} else {
req.log.error('database not available');
res.status(500).send('database not available');
}
});
// return all users for debugging only
app.get('/users', (req, res) => {
if(mongoConnected) {