From 9deb5adee1dafa1c6a976bf08e6c569ad308b6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 9 Sep 2021 00:33:11 +0200 Subject: [PATCH] MemberAlreadyExists returns UnprocessableEntity. --- internal/api/members/controler.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/api/members/controler.go b/internal/api/members/controler.go index a6a44a94..09f626d2 100644 --- a/internal/api/members/controler.go +++ b/internal/api/members/controler.go @@ -1,6 +1,7 @@ package members import ( + "errors" "net/http" "strconv" @@ -82,7 +83,11 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) { id, err := h.members.Insert(data.Username, data.Password, data.Profile) if err != nil { - utils.HttpInternalServerError(w, err) + if errors.Is(err, types.ErrMemberAlreadyExists) { + utils.HttpUnprocessableEntity(w, err) + } else { + utils.HttpInternalServerError(w, err) + } return }