From fc7cf5933facc55d1e68fc6bac16205bfc72982b Mon Sep 17 00:00:00 2001 From: Hunter Kehoe Date: Wed, 3 Apr 2024 21:58:43 -0600 Subject: [PATCH] fix error message for invalid username/password --- server/errors.go | 1 + server/server_account.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/errors.go b/server/errors.go index 657d1ddc0..5498d12f9 100644 --- a/server/errors.go +++ b/server/errors.go @@ -122,6 +122,7 @@ var ( errHTTPBadRequestTemplateInvalid = &errHTTP{40043, http.StatusBadRequest, "invalid request: could not parse template", "https://ntfy.sh/docs/publish/#message-templating", nil} errHTTPBadRequestTemplateDisallowedFunctionCalls = &errHTTP{40044, http.StatusBadRequest, "invalid request: template contains disallowed function calls, e.g. template, call, or define", "https://ntfy.sh/docs/publish/#message-templating", nil} errHTTPBadRequestTemplateExecuteFailed = &errHTTP{40045, http.StatusBadRequest, "invalid request: template execution failed", "https://ntfy.sh/docs/publish/#message-templating", nil} + errHTTPBadRequestInvalidArgument = &errHTTP{40046, http.StatusBadRequest, "invalid request: invalid argument", "", nil} errHTTPNotFound = &errHTTP{40401, http.StatusNotFound, "page not found", "", nil} errHTTPUnauthorized = &errHTTP{40101, http.StatusUnauthorized, "unauthorized", "https://ntfy.sh/docs/publish/#authentication", nil} errHTTPForbidden = &errHTTP{40301, http.StatusForbidden, "forbidden", "https://ntfy.sh/docs/publish/#authentication", nil} diff --git a/server/server_account.go b/server/server_account.go index cb841d077..31d581f19 100644 --- a/server/server_account.go +++ b/server/server_account.go @@ -37,7 +37,11 @@ func (s *Server) handleAccountCreate(w http.ResponseWriter, r *http.Request, v * } logvr(v, r).Tag(tagAccount).Field("user_name", newAccount.Username).Info("Creating user %s", newAccount.Username) if err := s.userManager.AddUser(newAccount.Username, newAccount.Password, user.RoleUser); err != nil { - return err + if err.Error() == "invalid argument" { + return errHTTPBadRequestInvalidArgument + } else { + return err + } } v.AccountCreated() return s.writeJSON(w, newSuccessResponse())