diff --git a/backend/src/api/members/routes.js b/backend/src/api/members/routes.js index d846e00..54b2c3a 100644 --- a/backend/src/api/members/routes.js +++ b/backend/src/api/members/routes.js @@ -36,7 +36,7 @@ module.exports = { const member = await controller.create(req.db, data); - if (!member) return res.sendStatus(400); // Duplicate user + if (!member) return res.sendStatus(409); // Duplicate user res.json(member); }, @@ -67,10 +67,13 @@ module.exports = { } catch (e) { return res.sendStatus(400); } - - const member = await controller.update(req.db, id, data); - - if (!member) return res.sendStatus(404); - res.json(member); + try { + const member = await controller.update(req.db, id, data); + if (!member) return res.sendStatus(404); + res.json(member); + } catch (e) { + if (e.code === 'ER_DUP_ENTRY') return res.sendStatus(409); + else throw e; + } }, }; diff --git a/frontend/src/api/httpClient.js b/frontend/src/api/httpClient.js index cc8634a..d301e7a 100644 --- a/frontend/src/api/httpClient.js +++ b/frontend/src/api/httpClient.js @@ -48,6 +48,14 @@ const errorInterceptor = (error) => { router.push('login'); break; + case 409: + Vue.notify({ + type: 'warn', + title: 'Duplicate Entry', + text: 'The server rejected the request', + }); + break; + case 500: console.error(error.response.status, error.message); Vue.notify({