Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
0026e871
Unverified
Commit
0026e871
authored
Dec 30, 2025
by
刀刀
Committed by
GitHub
Dec 30, 2025
Browse files
CC Stream 响应流中出现 error 时, 增加返回重试 (#86)
* 响应流中出现 error, 返回重试 * 响应流中出现 error, 返回重试
parent
942c3e15
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/handler/gateway_handler.go
View file @
0026e871
...
...
@@ -216,7 +216,7 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
}
}
const
maxAccountSwitches
=
3
const
maxAccountSwitches
=
10
switchCount
:=
0
failedAccountIDs
:=
make
(
map
[
int64
]
struct
{})
lastFailoverStatus
:=
0
...
...
backend/internal/service/gateway_service.go
View file @
0026e871
...
...
@@ -695,6 +695,11 @@ func (s *GatewayService) Forward(ctx context.Context, c *gin.Context, account *A
if
req
.
Stream
{
streamResult
,
err
:=
s
.
handleStreamingResponse
(
ctx
,
resp
,
c
,
account
,
startTime
,
originalModel
,
req
.
Model
)
if
err
!=
nil
{
if
err
.
Error
()
==
"have error in stream"
{
return
nil
,
&
UpstreamFailoverError
{
StatusCode
:
403
,
}
}
return
nil
,
err
}
usage
=
streamResult
.
usage
...
...
@@ -969,6 +974,9 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
for
scanner
.
Scan
()
{
line
:=
scanner
.
Text
()
if
line
==
"event: error"
{
return
nil
,
errors
.
New
(
"have error in stream"
)
}
// Extract data from SSE line (supports both "data: " and "data:" formats)
if
sseDataRe
.
MatchString
(
line
)
{
...
...
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