Harden feed/profile routes against invalid IDs and null profiles
This commit is contained in:
@@ -795,12 +795,24 @@ DB.getDB.then((DB) => {
|
||||
* $ref: '#/components/schemas/Profile'
|
||||
*/
|
||||
router.get("/:id", async (req, res) => {
|
||||
let profileId = req.params.id;
|
||||
let profile = await DB.getProfile(profileId);
|
||||
return res.json({
|
||||
status: "ok",
|
||||
...profile
|
||||
});
|
||||
try {
|
||||
let profileId = req.params.id;
|
||||
let profile = await DB.getProfile(profileId);
|
||||
if (!profile || !profile._id) {
|
||||
return res.status(404).json({
|
||||
status: "Profile not found",
|
||||
});
|
||||
}
|
||||
return res.json({
|
||||
status: "ok",
|
||||
...profile
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error loading profile", error);
|
||||
return res.status(500).json({
|
||||
status: "Internal server error"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -913,4 +925,4 @@ DB.getDB.then((DB) => {
|
||||
|
||||
});
|
||||
|
||||
module.exports = router
|
||||
module.exports = router
|
||||
|
||||
Reference in New Issue
Block a user