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
009333da
authored
Feb 21, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Improve quota error messages with formatted quota display
parent
23bfc06f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
service/quota.go
+3
-3
No files found.
service/quota.go
View file @
009333da
...
@@ -95,11 +95,11 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag
...
@@ -95,11 +95,11 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag
quota
:=
calculateAudioQuota
(
quotaInfo
)
quota
:=
calculateAudioQuota
(
quotaInfo
)
if
userQuota
<
quota
{
if
userQuota
<
quota
{
return
errors
.
New
(
fmt
.
Sprintf
(
"用户额度不足,剩余额度为 %d"
,
userQ
uota
))
return
fmt
.
Errorf
(
"user quota is not enough, user quota: %s, need quota: %s"
,
common
.
FormatQuota
(
userQuota
),
common
.
FormatQuota
(
q
uota
))
}
}
if
!
token
.
UnlimitedQuota
&&
token
.
RemainQuota
<
quota
{
if
!
token
.
UnlimitedQuota
&&
token
.
RemainQuota
<
quota
{
return
errors
.
New
(
fmt
.
Sprintf
(
"令牌额度不足,剩余额度为 %d"
,
token
.
RemainQ
uota
))
return
fmt
.
Errorf
(
"token quota is not enough, token remain quota: %s, need quota: %s"
,
common
.
FormatQuota
(
token
.
RemainQuota
),
common
.
FormatQuota
(
q
uota
))
}
}
err
=
PostConsumeQuota
(
relayInfo
,
quota
,
0
,
false
)
err
=
PostConsumeQuota
(
relayInfo
,
quota
,
0
,
false
)
...
@@ -262,7 +262,7 @@ func PreConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, quota int) error {
...
@@ -262,7 +262,7 @@ func PreConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, quota int) error {
return
err
return
err
}
}
if
!
relayInfo
.
TokenUnlimited
&&
token
.
RemainQuota
<
quota
{
if
!
relayInfo
.
TokenUnlimited
&&
token
.
RemainQuota
<
quota
{
return
errors
.
New
(
"令牌额度不足"
)
return
fmt
.
Errorf
(
"token quota is not enough, token remain quota: %s, need quota: %s"
,
common
.
FormatQuota
(
token
.
RemainQuota
),
common
.
FormatQuota
(
quota
)
)
}
}
err
=
model
.
DecreaseTokenQuota
(
relayInfo
.
TokenId
,
relayInfo
.
TokenKey
,
quota
)
err
=
model
.
DecreaseTokenQuota
(
relayInfo
.
TokenId
,
relayInfo
.
TokenKey
,
quota
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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