Better error handling

This commit is contained in:
xfarrow 2024-02-26 10:58:35 +01:00
parent 5b51c61011
commit 82e51832ef
4 changed files with 14 additions and 14 deletions

View File

@ -36,7 +36,7 @@ async function addOrganizationAdmin (req, res) {
await organization_admin_model.addOrganizationAdministrator(req.body.person_id, req.body.organization_id);
return res.status(200).json({ success: true });
} catch (error) {
console.error('Error while adding organization admin: ' + error);
console.error(`Error in function ${addOrganizationAdmin.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' });
}
}
@ -60,7 +60,7 @@ async function removeOrganizationAdmin (req, res) {
await organization_admin_model.removeOrganizationAdmin(req.jwt.person_id, req.body.organization_id);
return res.status(200).json({ success: true });
} catch (error) {
console.error(error);
console.error(`Error in function ${removeOrganizationAdmin.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}

View File

@ -36,7 +36,7 @@ async function createOrganizationPost (req, res) {
const insertedOrganization = await organizationPostModel.insertOrganizationPost(organization);
return res.status(200).json(insertedOrganization);
} catch (error) {
console.log(`Error while creating Organization Post: ${error}`);
console.error(`Error in function ${createOrganizationPost.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}
@ -59,7 +59,7 @@ async function deleteOrganizationPost (req, res) {
return res.status(401).json({ error: 'Forbidden' });
}
} catch (error) {
console.log(`Error while deleting Organization Post: ${error}`);
console.error(`Error in function ${deleteOrganizationPost.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' });
}
}

View File

@ -33,7 +33,7 @@ async function createOrganization (req, res) {
await organization_model.insertOrganization(organization, req.jwt.person_id);
return res.status(200).json({ Organization: organization });
} catch (error) {
console.error('Error creating Organization:', error);
console.error(`Error in function ${createOrganization.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' });
}
}
@ -75,7 +75,7 @@ async function updateOrganization (req, res) {
return res.status(404).json({ error: 'Organization either not found or insufficient permissions' });
}
} catch (error) {
console.log(error);
console.error(`Error in function ${updateOrganization.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}
@ -95,7 +95,7 @@ async function deleteOrganization (req, res) {
return res.status(200).json({ success: true });
}
} catch (error) {
console.error(error);
console.error(`Error in function ${deleteOrganization.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}
@ -118,7 +118,7 @@ async function getOrganization (req, res) {
return res.status(404).json({ error: 'Not found' });
}
} catch (error) {
console.error('Error retrieving an organization: ' + error);
console.error(`Error in function ${getOrganization.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}

View File

@ -62,7 +62,7 @@ async function registerPerson (req, res) {
await person_model.registerPerson(personToInsert, activationLink);
return res.status(200).json({ activationLink });
} catch (error) {
console.error('Error registering person:', error);
console.error(`Error in function ${console.trace()}: ${error}`);
res.status(500).json({ error: 'Internal server error' });
}
}
@ -92,7 +92,7 @@ async function login (req, res) {
res.status(401).json({ error: 'Unauthorized' });
}
} catch (error) {
console.error('Error logging in: ', error);
console.error(`Error in function ${login.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' });
}
}
@ -118,7 +118,7 @@ async function getPerson (req, res) {
}
return res.status(404).json({ error: 'Not found' });
} catch (error) {
console.log('Error while getting person: ' + error);
console.error(`Error in function ${getPerson.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}
@ -140,7 +140,7 @@ async function getMyself (req, res) {
}
return res.status(404).json({ error: 'Not found' });
} catch (error) {
console.log('Error while getting myself: ' + error);
console.error(`Error in function ${getMyself.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}
@ -204,7 +204,7 @@ async function updatePerson (req, res) {
await person_model.updatePerson(updatePerson, req.params.id);
return res.status(200).json({ success: 'true' });
} catch (error) {
console.log('Error while updating a Person: ' + error);
console.error(`Error in function ${updatePerson.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}
@ -224,7 +224,7 @@ async function deletePerson (req, res) {
await person_model.deletePerson(req.jwt.person_id);
return res.status(200).json({ success: true });
} catch (error) {
console.log('Error deleting a Person: ' + error);
console.error(`Error in function ${deletePerson.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' });
}
}