small fixes

This commit is contained in:
2025-06-18 09:01:14 +03:00
parent 42f2b68848
commit 5e609017f0
15 changed files with 55 additions and 108 deletions

View File

@@ -23,20 +23,16 @@ func (h *UserHandler) Register(w http.ResponseWriter, r *http.Request) {
err := h.Service.RegisterNewUser(r.Context(), req)
if err != nil {
// Определяем, какую ошибку вернуть клиенту
switch {
case errors.Is(err, database.ErrUserExists):
http.Error(w, err.Error(), http.StatusConflict) // 409
http.Error(w, err.Error(), http.StatusConflict)
case errors.Is(err, core.ErrInvalidUsername), errors.Is(err, core.ErrInvalidEmail), errors.Is(err, core.ErrPasswordTooShort):
http.Error(w, err.Error(), http.StatusBadRequest) // 400
http.Error(w, err.Error(), http.StatusBadRequest)
default:
// Логируем внутреннюю ошибку, но не показываем ее клиенту
// log.Printf("internal server error: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError) // 500
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
return
}
// Шаг 11 из ТЗ: Возвращаем 201 Created
w.WriteHeader(http.StatusCreated)
}