Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
12632982
Commit
12632982
authored
Dec 25, 2025
by
水玉婷
Browse files
feat:优化重连机制
parent
2dec9360
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/views/components/utils/sseService.ts
View file @
12632982
...
@@ -229,6 +229,30 @@ export class SSEService {
...
@@ -229,6 +229,30 @@ export class SSEService {
return
Math
.
min
(
this
.
RECONNECT_DELAY_BASE
*
Math
.
pow
(
2
,
this
.
reconnectAttempts
-
1
),
this
.
MAX_RECONNECT_DELAY
);
return
Math
.
min
(
this
.
RECONNECT_DELAY_BASE
*
Math
.
pow
(
2
,
this
.
reconnectAttempts
-
1
),
this
.
MAX_RECONNECT_DELAY
);
}
}
// 判断是否为服务器不可用错误
private
isServerUnavailableError
(
error
:
any
):
boolean
{
// 检查错误类型和消息,判断是否为真正的服务器不可用
const
errorMessage
=
error
?.
message
||
''
;
const
errorType
=
error
?.
type
||
''
;
// 服务器不可用的典型特征:
// 1. 连接被拒绝 (net::ERR_CONNECTION_REFUSED)
// 2. 服务器返回5xx错误
// 3. 连接超时但网络正常
const
isConnectionRefused
=
errorMessage
.
includes
(
'
CONNECTION_REFUSED
'
)
||
errorMessage
.
includes
(
'
connection refused
'
)
||
errorMessage
.
includes
(
'
Failed to fetch
'
);
const
isServerError
=
errorMessage
.
includes
(
'
500
'
)
||
errorMessage
.
includes
(
'
502
'
)
||
errorMessage
.
includes
(
'
503
'
)
||
errorMessage
.
includes
(
'
504
'
);
// 只有当明确是服务器不可用时才停止重连
// 避免将正常的网络波动误判为服务器不可用
return
isConnectionRefused
||
isServerError
;
}
// 处理网络恢复
// 处理网络恢复
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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