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
4c0c9ffd
authored
Aug 09, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add AWS invoke error handling and new error code
parent
8e52b42c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
relay/channel/aws/relay-aws.go
+4
-5
types/error.go
+1
-0
No files found.
relay/channel/aws/relay-aws.go
View file @
4c0c9ffd
package
aws
package
aws
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
...
@@ -113,14 +112,14 @@ func awsHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode int) (*
...
@@ -113,14 +112,14 @@ func awsHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode int) (*
}
}
claudeReq
:=
claudeReq_
.
(
*
dto
.
ClaudeRequest
)
claudeReq
:=
claudeReq_
.
(
*
dto
.
ClaudeRequest
)
awsClaudeReq
:=
copyRequest
(
claudeReq
)
awsClaudeReq
:=
copyRequest
(
claudeReq
)
awsReq
.
Body
,
err
=
js
on
.
Marshal
(
awsClaudeReq
)
awsReq
.
Body
,
err
=
comm
on
.
Marshal
(
awsClaudeReq
)
if
err
!=
nil
{
if
err
!=
nil
{
return
types
.
NewError
(
errors
.
Wrap
(
err
,
"marshal request"
),
types
.
ErrorCodeBadResponseBody
),
nil
return
types
.
NewError
(
errors
.
Wrap
(
err
,
"marshal request"
),
types
.
ErrorCodeBadResponseBody
),
nil
}
}
awsResp
,
err
:=
awsCli
.
InvokeModel
(
c
.
Request
.
Context
(),
awsReq
)
awsResp
,
err
:=
awsCli
.
InvokeModel
(
c
.
Request
.
Context
(),
awsReq
)
if
err
!=
nil
{
if
err
!=
nil
{
return
types
.
New
Error
(
errors
.
Wrap
(
err
,
"InvokeModel"
),
types
.
ErrorCodeChannelAwsClient
Error
),
nil
return
types
.
New
OpenAIError
(
errors
.
Wrap
(
err
,
"InvokeModel"
),
types
.
ErrorCodeAwsInvokeError
,
http
.
StatusInternalServer
Error
),
nil
}
}
claudeInfo
:=
&
claude
.
ClaudeResponseInfo
{
claudeInfo
:=
&
claude
.
ClaudeResponseInfo
{
...
@@ -165,14 +164,14 @@ func awsStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
...
@@ -165,14 +164,14 @@ func awsStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
claudeReq
:=
claudeReq_
.
(
*
dto
.
ClaudeRequest
)
claudeReq
:=
claudeReq_
.
(
*
dto
.
ClaudeRequest
)
awsClaudeReq
:=
copyRequest
(
claudeReq
)
awsClaudeReq
:=
copyRequest
(
claudeReq
)
awsReq
.
Body
,
err
=
js
on
.
Marshal
(
awsClaudeReq
)
awsReq
.
Body
,
err
=
comm
on
.
Marshal
(
awsClaudeReq
)
if
err
!=
nil
{
if
err
!=
nil
{
return
types
.
NewError
(
errors
.
Wrap
(
err
,
"marshal request"
),
types
.
ErrorCodeBadResponseBody
),
nil
return
types
.
NewError
(
errors
.
Wrap
(
err
,
"marshal request"
),
types
.
ErrorCodeBadResponseBody
),
nil
}
}
awsResp
,
err
:=
awsCli
.
InvokeModelWithResponseStream
(
c
.
Request
.
Context
(),
awsReq
)
awsResp
,
err
:=
awsCli
.
InvokeModelWithResponseStream
(
c
.
Request
.
Context
(),
awsReq
)
if
err
!=
nil
{
if
err
!=
nil
{
return
types
.
New
Error
(
errors
.
Wrap
(
err
,
"InvokeModelWithResponseStream"
),
types
.
ErrorCodeChannelAwsClient
Error
),
nil
return
types
.
New
OpenAIError
(
errors
.
Wrap
(
err
,
"InvokeModelWithResponseStream"
),
types
.
ErrorCodeAwsInvokeError
,
http
.
StatusInternalServer
Error
),
nil
}
}
stream
:=
awsResp
.
GetStream
()
stream
:=
awsResp
.
GetStream
()
defer
stream
.
Close
()
defer
stream
.
Close
()
...
...
types/error.go
View file @
4c0c9ffd
...
@@ -65,6 +65,7 @@ const (
...
@@ -65,6 +65,7 @@ const (
ErrorCodeBadResponse
ErrorCode
=
"bad_response"
ErrorCodeBadResponse
ErrorCode
=
"bad_response"
ErrorCodeBadResponseBody
ErrorCode
=
"bad_response_body"
ErrorCodeBadResponseBody
ErrorCode
=
"bad_response_body"
ErrorCodeEmptyResponse
ErrorCode
=
"empty_response"
ErrorCodeEmptyResponse
ErrorCode
=
"empty_response"
ErrorCodeAwsInvokeError
ErrorCode
=
"aws_invoke_error"
// sql error
// sql error
ErrorCodeQueryDataError
ErrorCode
=
"query_data_error"
ErrorCodeQueryDataError
ErrorCode
=
"query_data_error"
...
...
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