diff --git a/server/errors.go b/server/errors.go index 5498d12f..c6076f3f 100644 --- a/server/errors.go +++ b/server/errors.go @@ -122,7 +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} + errHTTPBadRequestInvalidUsername = &errHTTP{40046, http.StatusBadRequest, "invalid request: invalid username", "", 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 31d581f1..3f2368da 100644 --- a/server/server_account.go +++ b/server/server_account.go @@ -2,6 +2,7 @@ package server import ( "encoding/json" + "errors" "heckel.io/ntfy/v2/log" "heckel.io/ntfy/v2/user" "heckel.io/ntfy/v2/util" @@ -37,11 +38,10 @@ 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 { - if err.Error() == "invalid argument" { - return errHTTPBadRequestInvalidArgument - } else { - return err + if errors.Is(err, user.ErrInvalidArgument) { + return errHTTPBadRequestInvalidUsername } + return err } v.AccountCreated() return s.writeJSON(w, newSuccessResponse())