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