add: print req body on err resp (#67)

This commit is contained in:
Xinhao Zhuang
2023-09-27 19:05:53 +08:00
committed by GitHub
parent 7a8ef96d1f
commit 80330ec62a

View File

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