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) {