handle exceptions while adding the site
This commit is contained in:
@@ -36,16 +36,19 @@ router.get('/:id', async function(req, res, next) {
|
|||||||
*
|
*
|
||||||
* Creates a new site with the provided domain name.
|
* 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)
|
* // TODO: Ability to add additional site properties (e.g., name, description)
|
||||||
*/
|
*/
|
||||||
router.post('/add', async function(req, res, next) {
|
router.post('/add', async function(req, res, next) {
|
||||||
const domain = req.body.domain;
|
const domain = req.body.domain;
|
||||||
|
let newSite = null;
|
||||||
|
|
||||||
const newSite = await siteModel.insert(domain, domain);
|
// insert method passes a lot of validation errors to the caller
|
||||||
|
try {
|
||||||
console.log('New site created:', newSite);
|
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) {
|
if (!newSite) {
|
||||||
res.status(400).send('Error creating site');
|
res.status(400).send('Error creating site');
|
||||||
|
|||||||
Reference in New Issue
Block a user