Commit 12632982 authored by 水玉婷's avatar 水玉婷
Browse files

feat:优化重连机制

parent 2dec9360
...@@ -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;
}
// 处理网络恢复 // 处理网络恢复
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment