From 1e26c649129376c1986e70f5a59bd8cc3f9b7ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Fri, 25 Sep 2020 22:14:31 +0200 Subject: [PATCH] fix: Name conflict should return 409 closes #509 --- lib/routes/admin-api/util.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/routes/admin-api/util.js b/lib/routes/admin-api/util.js index 6d4ad7c9c9..fd6df1ad44 100644 --- a/lib/routes/admin-api/util.js +++ b/lib/routes/admin-api/util.js @@ -26,13 +26,17 @@ const nameType = customJoi const handleErrors = (res, logger, error) => { logger.warn(error.message); + // eslint-disable-next-line no-param-reassign + error.isJoi = true; switch (error.name) { case 'NotFoundError': return res.status(404).end(); case 'NameExistsError': + return res + .status(409) + .json(error) + .end(); case 'ValidationError': - // eslint-disable-next-line no-param-reassign - error.isJoi = true; return res .status(400) .json(error)