fix: resp body when error
This commit is contained in:
parent
d850f465cd
commit
164df4e708
@ -55,12 +55,16 @@ func testChannel(channel *model.Channel, request ChatRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
// Prinnt the body in string
|
// Print the body in string
|
||||||
|
if resp.Body != nil {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(resp.Body)
|
buf.ReadFrom(resp.Body)
|
||||||
return errors.New("error response: " + strconv.Itoa(resp.StatusCode) + " " + buf.String())
|
return errors.New("error response: " + strconv.Itoa(resp.StatusCode) + " " + buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return errors.New("error response: " + strconv.Itoa(resp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
var done = false
|
var done = false
|
||||||
var streamResponseText = ""
|
var streamResponseText = ""
|
||||||
|
|
||||||
|
@ -181,16 +181,14 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|||||||
return errorWrapper(err, "do_request_failed", http.StatusInternalServerError)
|
return errorWrapper(err, "do_request_failed", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
// Print Data if Error
|
// Print the body in string
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
if resp.Body != nil {
|
||||||
if err != nil {
|
buf := new(bytes.Buffer)
|
||||||
return errorWrapper(err, "read_response_body_failed", http.StatusInternalServerError)
|
buf.ReadFrom(resp.Body)
|
||||||
|
log.Printf("Error Channel (%s): %s", baseURL, buf.String())
|
||||||
|
return errorWrapper(err, "request_failed", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyString := string(bodyBytes)
|
|
||||||
|
|
||||||
log.Printf("Error: %s", bodyString)
|
|
||||||
|
|
||||||
return errorWrapper(err, "request_failed", resp.StatusCode)
|
return errorWrapper(err, "request_failed", resp.StatusCode)
|
||||||
}
|
}
|
||||||
err = req.Body.Close()
|
err = req.Body.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user