From c364e31ee38fbe5cdd7f563fec2a70e190f6184e Mon Sep 17 00:00:00 2001 From: Aarish <118203269+ImprobableGenius@users.noreply.github.com> Date: Sat, 24 May 2025 18:37:54 -0500 Subject: [PATCH] handle exceptions while adding the site --- routes/sites.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/routes/sites.js b/routes/sites.js index 9bf20b8..c6c8a38 100644 --- a/routes/sites.js +++ b/routes/sites.js @@ -36,16 +36,19 @@ router.get('/:id', async function(req, res, next) { * * Creates a new site with the provided domain name. * - * // TODO: Implement validation for domain name format - * // TODO: Implement error handling for duplicate domains * // TODO: Ability to add additional site properties (e.g., name, description) */ router.post('/add', async function(req, res, next) { const domain = req.body.domain; + let newSite = null; - const newSite = await siteModel.insert(domain, domain); - - console.log('New site created:', newSite); + // insert method passes a lot of validation errors to the caller + try { + newSite = await siteModel.insert(domain, domain); + } catch (error) { + console.error('Error creating site:', error); + return res.status(400).send('Error creating site: ' + error.message); + } if (!newSite) { res.status(400).send('Error creating site');