feat: 防止渠道地址传到用户端
This commit is contained in:
parent
b06c370fd9
commit
929cd79ee7
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -106,12 +107,18 @@ func countTokenText(text string, model string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func errorWrapper(err error, code string, statusCode int) *OpenAIErrorWithStatusCode {
|
func errorWrapper(err error, code string, statusCode int) *OpenAIErrorWithStatusCode {
|
||||||
if statusCode == http.StatusInternalServerError {
|
text := err.Error()
|
||||||
//避免暴露内部错误
|
// 定义一个正则表达式匹配URL
|
||||||
err = fmt.Errorf("internal server error")
|
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{
|
openAIError := OpenAIError{
|
||||||
Message: err.Error(),
|
Message: text,
|
||||||
Type: "one_api_error",
|
Type: "one_api_error",
|
||||||
Code: code,
|
Code: code,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user