Skip to content

Commit

Permalink
add duplicate entry error code notification for users #87
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoidmatos committed Aug 17, 2021
1 parent 301b25c commit c3adc3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions backend/src/api/members/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand Down Expand Up @@ -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;
}
},
};
8 changes: 8 additions & 0 deletions frontend/src/api/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit c3adc3e

Please sign in to comment.