fix: add HTTP status checks to GetUserByName; remove redundant FindHomePage check

GetUserByName made two REST requests without checking the HTTP status
codes. A 401/403/500 response would silently be treated as an empty
result set and return 'user not found' instead of the real error.
Add a status check after each request.

FindHomePage had 'StatusNotFound || != StatusOK' — the first clause
is always a subset of the second, making it dead code. Simplified to
just '!= StatusOK'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Manuel Rüger 2026-03-13 02:01:45 +01:00
parent 0d735203dd
commit ed6ae15500

View File

@ -180,7 +180,7 @@ func (api *API) FindHomePage(space string) (*PageInfo, error) {
return nil, err
}
if request.Raw.StatusCode == http.StatusNotFound || request.Raw.StatusCode != http.StatusOK {
if request.Raw.StatusCode != http.StatusOK {
return nil, newErrorStatusNotOK(request)
}
@ -691,7 +691,7 @@ func (api *API) GetUserByName(name string) (*User, error) {
}
// Try the new path first
_, err := api.rest.
request, err := api.rest.
Res("search").
Res("user", &response).
Get(map[string]string{
@ -700,10 +700,13 @@ func (api *API) GetUserByName(name string) (*User, error) {
if err != nil {
return nil, err
}
if request.Raw.StatusCode != http.StatusOK {
return nil, newErrorStatusNotOK(request)
}
// Try old path
if len(response.Results) == 0 {
_, err := api.rest.
request, err := api.rest.
Res("search", &response).
Get(map[string]string{
"cql": fmt.Sprintf("user.fullname~%q", name),
@ -711,6 +714,9 @@ func (api *API) GetUserByName(name string) (*User, error) {
if err != nil {
return nil, err
}
if request.Raw.StatusCode != http.StatusOK {
return nil, newErrorStatusNotOK(request)
}
}
if len(response.Results) == 0 {