Skip to content

Commit

Permalink
add: print req body on err resp
Browse files Browse the repository at this point in the history
  • Loading branch information
john-theo committed Sep 27, 2023
1 parent 7a8ef96 commit 4d9288f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions azure/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4d9288f

Please sign in to comment.