handle exceptions while adding the site

This commit is contained in:
Aarish
2025-05-24 18:37:54 -05:00
parent 061f9121b9
commit c364e31ee3

View File

@@ -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');