1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

Refactor HTTP Client and LocalizedError packages

This commit is contained in:
Frédéric Guillot 2023-10-21 19:50:29 -07:00
parent 120aabfbce
commit 14e25ab9fe
104 changed files with 1277 additions and 10672 deletions

View file

@ -9,6 +9,7 @@ import (
"miniflux.app/v2/internal/http/request"
"miniflux.app/v2/internal/http/response/html"
"miniflux.app/v2/internal/http/route"
"miniflux.app/v2/internal/locale"
"miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/ui/form"
"miniflux.app/v2/internal/ui/session"
@ -38,14 +39,14 @@ func (h *handler) saveUser(w http.ResponseWriter, r *http.Request) {
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
view.Set("form", userForm)
if err := userForm.ValidateCreation(); err != nil {
view.Set("errorMessage", err.Error())
if validationErr := userForm.ValidateCreation(); validationErr != nil {
view.Set("errorMessage", validationErr.Translate(user.Language))
html.OK(w, r, view.Render("create_user"))
return
}
if h.store.UserExists(userForm.Username) {
view.Set("errorMessage", "error.user_already_exists")
view.Set("errorMessage", locale.NewLocalizedError("error.user_already_exists").Translate(user.Language))
html.OK(w, r, view.Render("create_user"))
return
}
@ -57,7 +58,7 @@ func (h *handler) saveUser(w http.ResponseWriter, r *http.Request) {
}
if validationErr := validator.ValidateUserCreationWithPassword(h.store, userCreationRequest); validationErr != nil {
view.Set("errorMessage", validationErr.TranslationKey)
view.Set("errorMessage", validationErr.Translate(user.Language))
html.OK(w, r, view.Render("create_user"))
return
}