Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion server/controllers/project.controller/deleteProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export default async function deleteProject(req, res) {
res.status(error.code).json({ message: error.message });
};

function sendProjectNotFound() {
sendFailure(
new ProjectDeletionError('Project with that id does not exist', {
code: 404
})
);
}

try {
const project = await Project.findById(req.params.project_id);

Expand All @@ -60,6 +68,10 @@ export default async function deleteProject(req, res) {
await project.remove();
res.status(200).end();
} catch (error) {
sendFailure(error);
if (error.name === 'CastError' && error.kind === 'ObjectId') {
sendProjectNotFound();
} else {
sendFailure(error);
}
}
}