[bob] Log body of "Bad Request" responses (#19823)

This commit is contained in:
Gero Posmyk-Leinemann 2024-06-04 07:50:16 +02:00 committed by GitHub
parent 87fa7d0fcd
commit 43a156630f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ package proxy
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httputil"
"net/url"
@ -229,7 +230,12 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
return true, nil
}
if resp.StatusCode == http.StatusBadRequest {
log.WithField("URL", resp.Request.URL.String()).Warn("bad request")
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.WithError(err).WithField("URL", resp.Request.URL.String()).Warn("failed to read response body")
}
log.WithField("URL", resp.Request.URL.String()).WithField("Body", string(bodyBytes)).Warn("bad request")
return true, nil
}