From ed6ae155009c901a91c4b6837a551247a8e786f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 13 Mar 2026 02:01:45 +0100 Subject: [PATCH] fix: add HTTP status checks to GetUserByName; remove redundant FindHomePage check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- confluence/api.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/confluence/api.go b/confluence/api.go index 61ba7da..bf06cc1 100644 --- a/confluence/api.go +++ b/confluence/api.go @@ -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 {