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
3f2df317
authored
Jul 27, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: print user id when error
parent
c6dcdec9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
4 deletions
+6
-4
common/utils.go
+2
-2
controller/relay.go
+2
-1
middleware/utils.go
+2
-1
No files found.
common/utils.go
View file @
3f2df317
...
...
@@ -179,8 +179,8 @@ func Max(a int, b int) int {
}
}
func
MessageWithRequestId
(
message
string
,
id
string
)
string
{
return
fmt
.
Sprintf
(
"%s (request id: %s
)"
,
message
,
i
d
)
func
MessageWithRequestId
(
message
string
,
id
string
,
userId
int
)
string
{
return
fmt
.
Sprintf
(
"%s (request id: %s
, user id: %d)"
,
message
,
id
,
userI
d
)
}
func
RandomSleep
()
{
...
...
controller/relay.go
View file @
3f2df317
...
...
@@ -82,7 +82,8 @@ func Relay(c *gin.Context) {
if
openaiErr
.
StatusCode
==
http
.
StatusTooManyRequests
{
openaiErr
.
Error
.
Message
=
"当前分组上游负载已饱和,请稍后再试"
}
openaiErr
.
Error
.
Message
=
common
.
MessageWithRequestId
(
openaiErr
.
Error
.
Message
,
requestId
)
userId
:=
c
.
GetInt
(
"id"
)
openaiErr
.
Error
.
Message
=
common
.
MessageWithRequestId
(
openaiErr
.
Error
.
Message
,
requestId
,
userId
)
c
.
JSON
(
openaiErr
.
StatusCode
,
gin
.
H
{
"error"
:
openaiErr
.
Error
,
})
...
...
middleware/utils.go
View file @
3f2df317
...
...
@@ -6,9 +6,10 @@ import (
)
func
abortWithOpenAiMessage
(
c
*
gin
.
Context
,
statusCode
int
,
message
string
)
{
userId
:=
c
.
GetInt
(
"id"
)
c
.
JSON
(
statusCode
,
gin
.
H
{
"error"
:
gin
.
H
{
"message"
:
common
.
MessageWithRequestId
(
message
,
c
.
GetString
(
common
.
RequestIdKey
)),
"message"
:
common
.
MessageWithRequestId
(
message
,
c
.
GetString
(
common
.
RequestIdKey
)
,
userId
),
"type"
:
"new_api_error"
,
},
})
...
...
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