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
b311d482
authored
Jan 19, 2026
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update abortWithOpenAiMessage function to use types.ErrorCode
parent
5c1d43fc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
5 deletions
+7
-5
middleware/auth.go
+2
-1
middleware/distributor.go
+2
-2
middleware/utils.go
+3
-2
No files found.
middleware/auth.go
View file @
b311d482
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/ratio_setting"
"github.com/QuantumNous/new-api/setting/ratio_setting"
"github.com/QuantumNous/new-api/types"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -256,7 +257,7 @@ func TokenAuth() func(c *gin.Context) {
...
@@ -256,7 +257,7 @@ func TokenAuth() func(c *gin.Context) {
return
return
}
}
if
common
.
IsIpInCIDRList
(
ip
,
allowIps
)
==
false
{
if
common
.
IsIpInCIDRList
(
ip
,
allowIps
)
==
false
{
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
"您的 IP 不在令牌允许访问的列表中"
)
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
"您的 IP 不在令牌允许访问的列表中"
,
types
.
ErrorCodeAccessDenied
)
return
return
}
}
logger
.
LogDebug
(
c
,
"Client IP %s passed the token IP restrictions check"
,
clientIp
)
logger
.
LogDebug
(
c
,
"Client IP %s passed the token IP restrictions check"
,
clientIp
)
...
...
middleware/distributor.go
View file @
b311d482
...
@@ -114,11 +114,11 @@ func Distribute() func(c *gin.Context) {
...
@@ -114,11 +114,11 @@ func Distribute() func(c *gin.Context) {
// common.SysError(fmt.Sprintf("渠道不存在:%d", channel.Id))
// common.SysError(fmt.Sprintf("渠道不存在:%d", channel.Id))
// message = "数据库一致性已被破坏,请联系管理员"
// message = "数据库一致性已被破坏,请联系管理员"
//}
//}
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
message
,
string
(
types
.
ErrorCodeModelNotFound
)
)
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
message
,
types
.
ErrorCodeModelNotFound
)
return
return
}
}
if
channel
==
nil
{
if
channel
==
nil
{
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
fmt
.
Sprintf
(
"分组 %s 下模型 %s 无可用渠道(distributor)"
,
usingGroup
,
modelRequest
.
Model
),
string
(
types
.
ErrorCodeModelNotFound
)
)
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
fmt
.
Sprintf
(
"分组 %s 下模型 %s 无可用渠道(distributor)"
,
usingGroup
,
modelRequest
.
Model
),
types
.
ErrorCodeModelNotFound
)
return
return
}
}
}
}
...
...
middleware/utils.go
View file @
b311d482
...
@@ -5,13 +5,14 @@ import (
...
@@ -5,13 +5,14 @@ import (
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/logger"
"github.com/QuantumNous/new-api/logger"
"github.com/QuantumNous/new-api/types"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
)
func
abortWithOpenAiMessage
(
c
*
gin
.
Context
,
statusCode
int
,
message
string
,
code
...
string
)
{
func
abortWithOpenAiMessage
(
c
*
gin
.
Context
,
statusCode
int
,
message
string
,
code
...
types
.
ErrorCode
)
{
codeStr
:=
""
codeStr
:=
""
if
len
(
code
)
>
0
{
if
len
(
code
)
>
0
{
codeStr
=
code
[
0
]
codeStr
=
string
(
code
[
0
])
}
}
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
c
.
JSON
(
statusCode
,
gin
.
H
{
c
.
JSON
(
statusCode
,
gin
.
H
{
...
...
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