소스 검색

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({