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
13301d85
authored
Aug 23, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: enhance error handling for invalid request types in relay handlers
parent
060ce892
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
9 additions
and
9 deletions
+9
-9
common/gin.go
+2
-1
relay/claude_handler.go
+1
-1
relay/compatible_handler.go
+1
-2
relay/embedding_handler.go
+1
-1
relay/gemini_handler.go
+1
-1
relay/image_handler.go
+1
-1
relay/rerank_handler.go
+1
-1
relay/responses_handler.go
+1
-1
No files found.
common/gin.go
View file @
13301d85
...
...
@@ -2,12 +2,13 @@ package common
import
(
"bytes"
"github.com/gin-gonic/gin"
"io"
"net/http"
"one-api/constant"
"strings"
"time"
"github.com/gin-gonic/gin"
)
const
KeyRequestBody
=
"key_request_body"
...
...
relay/claude_handler.go
View file @
13301d85
...
...
@@ -24,7 +24,7 @@ func ClaudeHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
claudeReq
,
ok
:=
info
.
Request
.
(
*
dto
.
ClaudeRequest
)
if
!
ok
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"invalid request type, expected *dto.ClaudeRequest, got %T"
,
info
.
Request
))
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected *dto.ClaudeRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
(
))
}
request
,
err
:=
common
.
DeepCopy
(
claudeReq
)
...
...
relay/compatible_handler.go
View file @
13301d85
...
...
@@ -29,8 +29,7 @@ func TextHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *types
textReq
,
ok
:=
info
.
Request
.
(
*
dto
.
GeneralOpenAIRequest
)
if
!
ok
{
//return types.NewErrorWithStatusCode(errors.New("invalid request type"), types.ErrorCodeInvalidRequest, http.StatusBadRequest, types.ErrOptionWithSkipRetry())
common
.
FatalLog
(
"invalid request type, expected dto.GeneralOpenAIRequest, got %T"
,
info
.
Request
)
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected dto.GeneralOpenAIRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
())
}
request
,
err
:=
common
.
DeepCopy
(
textReq
)
...
...
relay/embedding_handler.go
View file @
13301d85
...
...
@@ -20,7 +20,7 @@ func EmbeddingHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *
embeddingReq
,
ok
:=
info
.
Request
.
(
*
dto
.
EmbeddingRequest
)
if
!
ok
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"invalid request type, expected *dto.EmbeddingRequest, got %T"
,
info
.
Request
))
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected *dto.EmbeddingRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
(
))
}
request
,
err
:=
common
.
DeepCopy
(
embeddingReq
)
...
...
relay/gemini_handler.go
View file @
13301d85
...
...
@@ -55,7 +55,7 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
geminiReq
,
ok
:=
info
.
Request
.
(
*
dto
.
GeminiChatRequest
)
if
!
ok
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"invalid request type, expected *dto.GeminiChatRequest, got %T"
,
info
.
Request
))
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected *dto.GeminiChatRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
(
))
}
request
,
err
:=
common
.
DeepCopy
(
geminiReq
)
...
...
relay/image_handler.go
View file @
13301d85
...
...
@@ -24,7 +24,7 @@ func ImageHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *type
imageReq
,
ok
:=
info
.
Request
.
(
*
dto
.
ImageRequest
)
if
!
ok
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"invalid request type, expected dto.ImageRequest, got %T"
,
info
.
Request
))
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected dto.ImageRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
(
))
}
request
,
err
:=
common
.
DeepCopy
(
imageReq
)
...
...
relay/rerank_handler.go
View file @
13301d85
...
...
@@ -21,7 +21,7 @@ func RerankHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
rerankReq
,
ok
:=
info
.
Request
.
(
*
dto
.
RerankRequest
)
if
!
ok
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"invalid request type, expected dto.RerankRequest, got %T"
,
info
.
Request
))
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected dto.RerankRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
(
))
}
request
,
err
:=
common
.
DeepCopy
(
rerankReq
)
...
...
relay/responses_handler.go
View file @
13301d85
...
...
@@ -22,7 +22,7 @@ func ResponsesHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *
responsesReq
,
ok
:=
info
.
Request
.
(
*
dto
.
OpenAIResponsesRequest
)
if
!
ok
{
common
.
FatalLog
(
fmt
.
Sprintf
(
"invalid request type, expected dto.OpenAIResponsesRequest, got %T"
,
info
.
Request
))
return
types
.
NewErrorWithStatusCode
(
fmt
.
Errorf
(
"invalid request type, expected dto.OpenAIResponsesRequest, got %T"
,
info
.
Request
),
types
.
ErrorCodeInvalidRequest
,
http
.
StatusBadRequest
,
types
.
ErrOptionWithSkipRetry
(
))
}
request
,
err
:=
common
.
DeepCopy
(
responsesReq
)
...
...
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