ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
25
services/stalwart/cmd/controller/http_error.go
Normal file
25
services/stalwart/cmd/controller/http_error.go
Normal 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)
|
||||
}
|
||||
Loading…
Reference in a new issue