handle errors thrown by model incase there is any error while fetching the site

This commit is contained in:
Aarish
2025-05-25 16:58:34 -05:00
parent 512d18ec23
commit b9967a8e66

View File

@@ -21,8 +21,14 @@ router.get('/', async function(req, res, next) {
*/ */
router.get('/:id', async function(req, res, next) { router.get('/:id', async function(req, res, next) {
const siteId = req.params.id; const siteId = req.params.id;
let site = null;
const site = await siteModel.getById(siteId); try {
site = await siteModel.getById(siteId);
} catch (error) {
console.error('Error fetching site by ID:', error);
return res.status(400).send('Error fetching site: ' + error.message);
}
if (!site) { if (!site) {
return res.status(404).send('Site not found'); return res.status(404).send('Site not found');