Skip to content

Commit 80330ec

Browse files
authored
add: print req body on err resp (#67)
1 parent 7a8ef96 commit 80330ec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

azure/proxy.go

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
3131
return
3232
}
3333

34+
// preserve request body for error logging
35+
var buf bytes.Buffer
36+
tee := io.TeeReader(c.Request.Body, &buf)
37+
bodyBytes, err := io.ReadAll(tee)
38+
if err != nil {
39+
log.Printf("Error reading request body: %v", err)
40+
return
41+
}
42+
c.Request.Body = io.NopCloser(&buf)
43+
3444
director := func(req *http.Request) {
3545
if req.Body == nil {
3646
util.SendError(c, errors.New("request body is empty"))
@@ -102,6 +112,10 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
102112
log.Printf("rewrite response error: %v", err)
103113
}
104114
}
115+
116+
if c.Writer.Status() != 200 {
117+
log.Printf("encountering error with body: %s", string(bodyBytes))
118+
}
105119
}
106120

107121
func GetDeploymentByModel(model string) (*DeploymentConfig, error) {

0 commit comments

Comments
 (0)