Skip to content

Commit

Permalink
fix error message for invalid username/password
Browse files Browse the repository at this point in the history
  • Loading branch information
wunter8 committed Apr 4, 2024
1 parent e4d22eb commit fc7cf59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 5 additions & 1 deletion server/server_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit fc7cf59

Please sign in to comment.