This commit is contained in:
CaIon
2023-09-09 01:50:41 +08:00
parent fe94656260
commit 43be1982d7
5 changed files with 43 additions and 21 deletions

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"io"
"log"
"net/http"
"one-api/common"
"one-api/model"
@@ -331,18 +330,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
isStream = isStream || strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream")
if resp.StatusCode != http.StatusOK {
//print resp body
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Println("read resp err body failed", err)
}
log.Println("resp body:", string(body))
errStr := fmt.Sprintf("bad status code: %d", resp.StatusCode)
if resp.StatusCode == 503 {
errStr = string(body)
}
return errorWrapper(
fmt.Errorf(errStr), "bad_status_code", resp.StatusCode)
return relayErrorHandler(resp)
}
}