feat: 避免请求出错时暴露渠道信息

This commit is contained in:
CaIon
2023-09-15 17:50:54 +08:00
parent d9deda18c1
commit d1d789616f
3 changed files with 12 additions and 2 deletions

View File

@@ -106,6 +106,10 @@ func countTokenText(text string, model string) int {
}
func errorWrapper(err error, code string, statusCode int) *OpenAIErrorWithStatusCode {
if statusCode == http.StatusInternalServerError {
//避免暴露内部错误
err = fmt.Errorf("internal server error")
}
openAIError := OpenAIError{
Message: err.Error(),
Type: "one_api_error",

View File

@@ -223,7 +223,7 @@ func Relay(c *gin.Context) {
c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("%s?retry=%d", c.Request.URL.Path, retryTimes-1))
} else {
if err.StatusCode == http.StatusTooManyRequests {
err.OpenAIError.Message = "当前分组上游负载已饱和,请稍后再试"
//err.OpenAIError.Message = "当前分组上游负载已饱和,请稍后再试"
}
c.JSON(err.StatusCode, gin.H{
"error": err.OpenAIError,