Catch errors when invalid data is received from Reddit in the user route

This commit is contained in:
ConcordOne 2023-06-06 20:19:01 +03:00
parent b0ce6c52a6
commit 8d800e490c
No known key found for this signature in database
GPG Key ID: CA30132D61A7FF7F
1 changed files with 9 additions and 0 deletions

View File

@ -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(