浏览代码

Add custom error for unique constraint error

sbkwgh 8 年之前
父节点
当前提交
4493ddebeb
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      routes/user.js

+ 5 - 1
routes/user.js

@@ -42,12 +42,16 @@ router.post('/', async (req, res) => {
 
 		res.json(user.toJSON())
 	} catch (err) {
-		console.log(err)
 		if(err === Errors.VALIDATION_ERROR) {
 			res.status(400)
 			res.json({
 				errors: validationErrors
 			})
+		} else if(err.name === 'SequelizeUniqueConstraintError') {
+			res.status(400)
+			res.json({
+				errors: [Errors.accountAlreadyCreated]
+			})
 		} else {
 			res.status(500)
 			res.json({