mirror of
https://github.com/stulzq/azure-openai-proxy.git
synced 2025-12-19 07:14:21 +01:00
add: print req body on err resp (#67)
This commit is contained in:
@@ -31,6 +31,16 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
|
|||||||
return
|
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) {
|
director := func(req *http.Request) {
|
||||||
if req.Body == nil {
|
if req.Body == nil {
|
||||||
util.SendError(c, errors.New("request body is empty"))
|
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)
|
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) {
|
func GetDeploymentByModel(model string) (*DeploymentConfig, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user