From 8d800e490c0e8c4f46079e6af33473fc76844406 Mon Sep 17 00:00:00 2001 From: ConcordOne Date: Tue, 6 Jun 2023 20:19:01 +0300 Subject: [PATCH] Catch errors when invalid data is received from Reddit in the user route --- routes/user.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/routes/user.js b/routes/user.js index eb383b7..4b7fb1c 100644 --- a/routes/user.js +++ b/routes/user.js @@ -206,6 +206,15 @@ userRoutes.get('/u/:user/:kind?', (req, res, next) => { } } ); + }).catch(error => { + console.error(`Something went wrong while fetching data from Reddit API: invalid or non-JSON data was returned.`); + return res.render('frontpage', { + json: null, + http_status_code: 500, + http_statustext: "Invalid response from Reddit", + user_preferences: req.cookies, + instance_config: config, + }); }); } else { console.error(