From 2922d98adbbded81641173c10989d591e7411635 Mon Sep 17 00:00:00 2001 From: Killerrekt Date: Sat, 16 Mar 2024 00:17:58 +0530 Subject: [PATCH] fix: if name already exists in update team it send status conflict --- internal/controllers/team_controller.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/controllers/team_controller.go b/internal/controllers/team_controller.go index 0d66844..bf95386 100644 --- a/internal/controllers/team_controller.go +++ b/internal/controllers/team_controller.go @@ -131,6 +131,15 @@ func UpdateTeamName(ctx echo.Context) error { err := services.UpdateTeamName(payload.Name, user.TeamID) if err != nil { + var pgerr *pgconn.PgError + if errors.As(err, &pgerr) { + if pgerr.Code == "23505" { + return ctx.JSON(http.StatusConflict, map[string]string{ + "message": "team name already exists", + "status": "failed to update team", + }) + } + } return ctx.JSON(http.StatusInternalServerError, map[string]string{ "message": err.Error(), "status": "error",