feat(ui): improve CloneManager with error handling
- Add loading state during clone creation - Add error display for failed operations - Add retry/refresh functionality - Improve gateway-client error handling Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -439,8 +439,10 @@ export class GatewayClient {
|
||||
// Check if OpenFang API is healthy
|
||||
const health = await this.restGet<{ status: string; version?: string }>('/api/health');
|
||||
if (health.status === 'ok') {
|
||||
this.reconnectAttempts = 0;
|
||||
this.setState('connected');
|
||||
this.log('info', `Connected to OpenFang via REST API${health.version ? ` (v${health.version})` : ''}`);
|
||||
this.emitEvent('connected', { version: health.version });
|
||||
} else {
|
||||
throw new Error('Health check failed');
|
||||
}
|
||||
@@ -1588,15 +1590,32 @@ export class GatewayClient {
|
||||
this.setState('disconnected');
|
||||
}
|
||||
|
||||
private static readonly MAX_RECONNECT_ATTEMPTS = 10;
|
||||
|
||||
private scheduleReconnect() {
|
||||
if (this.reconnectAttempts >= GatewayClient.MAX_RECONNECT_ATTEMPTS) {
|
||||
this.log('error', `Max reconnect attempts (${GatewayClient.MAX_RECONNECT_ATTEMPTS}) reached. Please reconnect manually.`);
|
||||
this.setState('disconnected');
|
||||
this.emitEvent('reconnect_failed', {
|
||||
attempts: this.reconnectAttempts,
|
||||
maxAttempts: GatewayClient.MAX_RECONNECT_ATTEMPTS
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.reconnectAttempts++;
|
||||
this.setState('reconnecting');
|
||||
const delay = Math.min(this.reconnectInterval * Math.pow(1.5, this.reconnectAttempts - 1), 30000);
|
||||
|
||||
this.log('info', `Scheduling reconnect attempt ${this.reconnectAttempts} in ${delay}ms`);
|
||||
|
||||
this.reconnectTimer = window.setTimeout(async () => {
|
||||
try {
|
||||
await this.connect();
|
||||
} catch { /* close handler will trigger another reconnect */ }
|
||||
} catch {
|
||||
/* close handler will trigger another reconnect */
|
||||
this.log('warn', `Reconnect attempt ${this.reconnectAttempts} failed`);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user