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
7e698f65
authored
Aug 28, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(pre_consume_quota): improve error messages for insufficient user quota
parent
906f797b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 additions
and
2 deletions
+1
-2
service/pre_consume_quota.go
+1
-2
No files found.
service/pre_consume_quota.go
View file @
7e698f65
package
service
package
service
import
(
import
(
"errors"
"fmt"
"fmt"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
...
@@ -36,7 +35,7 @@ func PreConsumeQuota(c *gin.Context, preConsumedQuota int, relayInfo *relaycommo
...
@@ -36,7 +35,7 @@ func PreConsumeQuota(c *gin.Context, preConsumedQuota int, relayInfo *relaycommo
return
0
,
types
.
NewError
(
err
,
types
.
ErrorCodeQueryDataError
,
types
.
ErrOptionWithSkipRetry
())
return
0
,
types
.
NewError
(
err
,
types
.
ErrorCodeQueryDataError
,
types
.
ErrOptionWithSkipRetry
())
}
}
if
userQuota
<=
0
{
if
userQuota
<=
0
{
return
0
,
types
.
NewErrorWithStatusCode
(
errors
.
New
(
"user quota is not enough"
),
types
.
ErrorCodeInsufficientUserQuota
,
http
.
StatusForbidden
,
types
.
ErrOptionWithSkipRetry
(),
types
.
ErrOptionWithNoRecordErrorLog
())
return
0
,
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"用户额度不足, 剩余额度: %s"
,
logger
.
FormatQuota
(
userQuota
)
),
types
.
ErrorCodeInsufficientUserQuota
,
http
.
StatusForbidden
,
types
.
ErrOptionWithSkipRetry
(),
types
.
ErrOptionWithNoRecordErrorLog
())
}
}
if
userQuota
-
preConsumedQuota
<
0
{
if
userQuota
-
preConsumedQuota
<
0
{
return
0
,
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"预扣费额度失败, 用户剩余额度: %s, 需要预扣费额度: %s"
,
logger
.
FormatQuota
(
userQuota
),
logger
.
FormatQuota
(
preConsumedQuota
)),
types
.
ErrorCodeInsufficientUserQuota
,
http
.
StatusForbidden
,
types
.
ErrOptionWithSkipRetry
(),
types
.
ErrOptionWithNoRecordErrorLog
())
return
0
,
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"预扣费额度失败, 用户剩余额度: %s, 需要预扣费额度: %s"
,
logger
.
FormatQuota
(
userQuota
),
logger
.
FormatQuota
(
preConsumedQuota
)),
types
.
ErrorCodeInsufficientUserQuota
,
http
.
StatusForbidden
,
types
.
ErrOptionWithSkipRetry
(),
types
.
ErrOptionWithNoRecordErrorLog
())
...
...
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