fix: defer body.Close() before ReadAll to ensure it runs on read error

The defer was placed after io.ReadAll, so if ReadAll returned an
error the body would not be closed. Move the defer before the read.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Manuel Rüger 2026-03-13 01:14:04 +01:00
parent a4ef890247
commit 9184e91268

View File

@ -824,11 +824,12 @@ func newErrorStatusNotOK(request *gopencils.Resource) error {
)
}
output, _ := io.ReadAll(request.Raw.Body)
defer func() {
_ = request.Raw.Body.Close()
}()
output, _ := io.ReadAll(request.Raw.Body)
return fmt.Errorf(
"the Confluence API returned unexpected status: %v, "+
"output: %q",