feat: 初步重构

This commit is contained in:
1808837298@qq.com
2024-02-29 01:08:18 +08:00
parent 9b421478c1
commit 5b18cd6b0a
67 changed files with 2646 additions and 2243 deletions

29
service/error.go Normal file
View File

@@ -0,0 +1,29 @@
package service
import (
"fmt"
"one-api/common"
"one-api/dto"
"strings"
)
// OpenAIErrorWrapper wraps an error into an OpenAIErrorWithStatusCode
func OpenAIErrorWrapper(err error, code string, statusCode int) *dto.OpenAIErrorWithStatusCode {
text := err.Error()
// 定义一个正则表达式匹配URL
if strings.Contains(text, "Post") {
common.SysLog(fmt.Sprintf("error: %s", text))
text = "请求上游地址失败"
}
//避免暴露内部错误
openAIError := dto.OpenAIError{
Message: text,
Type: "new_api_error",
Code: code,
}
return &dto.OpenAIErrorWithStatusCode{
OpenAIError: openAIError,
StatusCode: statusCode,
}
}