ce7cb702218693d08ea6d83464d2457c9250027c

This commit is contained in:
ms2k 2026-11-12 20:46:28 +09:00
commit 34c5f8963c

View file

@ -0,0 +1,25 @@
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func responseStatusError(action string, response *http.Response, secrets ...string) error {
body, err := io.ReadAll(io.LimitReader(response.Body, 4096))
if err != nil {
return fmt.Errorf("%s: HTTP %d", action, response.StatusCode)
}
detail := strings.TrimSpace(string(body))
for _, secret := range secrets {
if secret != "" {
detail = strings.ReplaceAll(detail, secret, "[redacted]")
}
}
if detail == "" {
return fmt.Errorf("%s: HTTP %d", action, response.StatusCode)
}
return fmt.Errorf("%s: HTTP %d: %q", action, response.StatusCode, detail)
}