diff --git a/backend/src/terminal/terminal.gateway.ts b/backend/src/terminal/terminal.gateway.ts index 35b7612..8f6d11e 100644 --- a/backend/src/terminal/terminal.gateway.ts +++ b/backend/src/terminal/terminal.gateway.ts @@ -45,16 +45,22 @@ export class TerminalGateway { private async handleMessage(client: any, msg: any) { switch (msg.type) { case 'connect': { - const sessionId = await this.ssh.connect( - msg.hostId, - (data) => this.send(client, { type: 'data', sessionId, data }), - (reason) => this.send(client, { type: 'disconnected', sessionId, reason }), - async (fingerprint, isNew) => { - // Send verification request to client - this.send(client, { type: 'host-key-verify', fingerprint, isNew }); - return true; // auto-accept for now, full flow in Task 12 - }, - ); + let sessionId = ''; + try { + sessionId = await this.ssh.connect( + msg.hostId, + (data) => this.send(client, { type: 'data', sessionId, data }), + (reason) => this.send(client, { type: 'disconnected', sessionId, reason }), + async (fingerprint, isNew) => { + this.send(client, { type: 'host-key-verify', fingerprint, isNew }); + return true; // auto-accept for now, full flow in Task 12 + }, + ); + } catch (err: any) { + this.logger.error(`[WS] SSH connect failed: ${err.message}`); + this.send(client, { type: 'error', message: `Connection failed: ${err.message}` }); + break; + } const sessions = this.clientSessions.get(client) || []; sessions.push(sessionId); this.clientSessions.set(client, sessions);