Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions app/Constants/errorCodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
errorCodes: {
DupKeyError: {
code: 11000,
message: 'Duplicate key error'
}
}
};
5 changes: 4 additions & 1 deletion app/Controllers/AuthController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const bcrypt = require('bcryptjs')
const jwt = require('jsonwebtoken')
const UserSchema = pxl.Model('User')
const { validationResult } = require('express-validator')
const { errorCodes } = require('../Constants/errorCodes');

class AuthController {
// Sign up controller
Expand Down Expand Up @@ -32,7 +33,9 @@ class AuthController {
'Successfully signed up and vertification code sent to your email.'
})
} catch (error) {
return next(error)
if (error.code && error.code === errorCodes.DupKeyError.code) {
res.status(400).json({ error: { ...errorCodes.DupKeyError } });
}
}
}

Expand Down