From 929cd79ee799ccc27f80057e20c07743b606124f Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Wed, 27 Sep 2023 01:02:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=B2=E6=AD=A2=E6=B8=A0=E9=81=93?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=BC=A0=E5=88=B0=E7=94=A8=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/relay-utils.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/controller/relay-utils.go b/controller/relay-utils.go index 0b132522..494186e3 100644 --- a/controller/relay-utils.go +++ b/controller/relay-utils.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "one-api/common" + "regexp" "strconv" ) @@ -106,12 +107,18 @@ 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") + text := err.Error() + // 定义一个正则表达式匹配URL + urlPattern := `http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+` + + urlRegexp, reErr := regexp.Compile(urlPattern) + if reErr == nil { + text = urlRegexp.ReplaceAllString(text, "https://api.openai.com") } + //避免暴露内部错误 + openAIError := OpenAIError{ - Message: err.Error(), + Message: text, Type: "one_api_error", Code: code, }