Skip to content

Commit 0ebd37f

Browse files
committed
Merge branch 'golang-gorm-crud-api'
2 parents 06db85d + 0a9c03e commit 0ebd37f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

controllers/auth.controller.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ func (ac *AuthController) SignUpUser(ctx *gin.Context) {
5656

5757
result := ac.DB.Create(&newUser)
5858

59-
if result.Error != nil {
60-
if strings.Contains(result.Error.Error(), "duplicate key") {
61-
ctx.JSON(http.StatusConflict, gin.H{"status": "fail", "message": "User with that email already exists"})
62-
return
63-
}
59+
if result.Error != nil && strings.Contains(result.Error.Error(), "duplicate key value violates unique") {
60+
ctx.JSON(http.StatusConflict, gin.H{"status": "fail", "message": "User with that email already exists"})
61+
return
62+
} else if result.Error != nil {
6463
ctx.JSON(http.StatusBadGateway, gin.H{"status": "error", "message": "Something bad happened"})
6564
return
6665
}

0 commit comments

Comments
 (0)