Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
46425139
authored
Aug 14, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 避免暴露内部错误
parent
a39766f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
8 deletions
+4
-8
service/error.go
+4
-8
No files found.
service/error.go
View file @
46425139
...
...
@@ -28,13 +28,11 @@ func MidjourneyErrorWithStatusCodeWrapper(code int, desc string, statusCode int)
// 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"
)
||
strings
.
Contains
(
text
,
"dial
"
)
{
lowerText
:=
strings
.
ToLower
(
text
)
if
strings
.
Contains
(
lowerText
,
"post"
)
||
strings
.
Contains
(
lowerText
,
"dial"
)
||
strings
.
Contains
(
lowerText
,
"http
"
)
{
common
.
SysLog
(
fmt
.
Sprintf
(
"error: %s"
,
text
))
text
=
"请求上游地址失败"
}
//避免暴露内部错误
openAIError
:=
dto
.
OpenAIError
{
Message
:
text
,
Type
:
"new_api_error"
,
...
...
@@ -113,14 +111,12 @@ func TaskErrorWrapperLocal(err error, code string, statusCode int) *dto.TaskErro
func
TaskErrorWrapper
(
err
error
,
code
string
,
statusCode
int
)
*
dto
.
TaskError
{
text
:=
err
.
Error
()
// 定义一个正则表达式匹配URL
if
strings
.
Contains
(
text
,
"Post"
)
||
strings
.
Contains
(
text
,
"dial"
)
{
lowerText
:=
strings
.
ToLower
(
text
)
if
strings
.
Contains
(
lowerText
,
"post"
)
||
strings
.
Contains
(
lowerText
,
"dial"
)
||
strings
.
Contains
(
lowerText
,
"http"
)
{
common
.
SysLog
(
fmt
.
Sprintf
(
"error: %s"
,
text
))
text
=
"请求上游地址失败"
}
//避免暴露内部错误
taskError
:=
&
dto
.
TaskError
{
Code
:
code
,
Message
:
text
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment