From ac7792ab371f8ee17804539b564a4a13b539ab73 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 9 Nov 2021 23:15:50 +0100 Subject: Handle missing users. --- server.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index b61ca8c..ef2684f 100644 --- a/server.js +++ b/server.js @@ -1536,10 +1536,15 @@ app.get('/games', must_be_logged_in, function (req, res) { app.get('/user/:who_id', function (req, res) { LOG(req, "GET /user/" + req.params.who_id); let who = sql_fetch_user_by_name.get(req.params.who_id, req.params.who_id); - who.avatar = get_avatar(who.mail); - who.ctime = human_date(who.ctime); - who.atime = human_date(who.atime); - res.render('user.ejs', { user: req.user, who: who, message: req.flash('message') }); + if (who) { + who.avatar = get_avatar(who.mail); + who.ctime = human_date(who.ctime); + who.atime = human_date(who.atime); + res.render('user.ejs', { user: req.user, who: who, message: req.flash('message') }); + } else { + req.flash('message', "Cannot find that user."); + return res.redirect('/'); + } }); // FORUM -- cgit v1.2.3