From 4d9288fbcbb0547e3c6fc2c3d202d32f02828026 Mon Sep 17 00:00:00 2001 From: John Dope Date: Wed, 27 Sep 2023 09:20:13 +0000 Subject: [PATCH] add: print req body on err resp --- azure/proxy.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/azure/proxy.go b/azure/proxy.go index 4b9d511..2cbca31 100644 --- a/azure/proxy.go +++ b/azure/proxy.go @@ -31,6 +31,16 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) { return } + // preserve request body for error logging + var buf bytes.Buffer + tee := io.TeeReader(c.Request.Body, &buf) + bodyBytes, err := io.ReadAll(tee) + if err != nil { + log.Printf("Error reading request body: %v", err) + return + } + c.Request.Body = io.NopCloser(&buf) + director := func(req *http.Request) { if req.Body == nil { util.SendError(c, errors.New("request body is empty")) @@ -102,6 +112,10 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) { log.Printf("rewrite response error: %v", err) } } + + if c.Writer.Status() != 200 { + log.Printf("encountering error with body: %s", string(bodyBytes)) + } } func GetDeploymentByModel(model string) (*DeploymentConfig, error) {