admin: close the response body on error paths too, and don't use the response body as a format string.

This commit is contained in:
Yasuhiro Matsumoto
2026-07-15 08:35:58 +09:00
parent 1cb730f34d
commit c525a25e51

View File

@@ -132,6 +132,7 @@ var admin = &cli.Command{
continue
}
b, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log("failed to read response: %s\n", err)
continue
@@ -142,7 +143,7 @@ var admin = &cli.Command{
if len(bodyPrintable) > 300 {
bodyPrintable = bodyPrintable[0:297] + "..."
}
log(bodyPrintable)
log("%s", bodyPrintable)
continue
}
var response nip86.Response
@@ -152,10 +153,9 @@ var admin = &cli.Command{
if len(bodyPrintable) > 300 {
bodyPrintable = bodyPrintable[0:297] + "..."
}
log(bodyPrintable)
log("%s", bodyPrintable)
continue
}
resp.Body.Close()
// print the result
log("\n")