1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

fix: improve error handling in SSH connection

This commit is contained in:
2025-02-12 18:10:27 +01:00
parent 49a3589536
commit 704f70819b
4 changed files with 23 additions and 10 deletions

View File

@ -64,9 +64,9 @@ export default (connections: Record<string, antares.Client>) => {
username: conn.sshUser, username: conn.sshUser,
password: conn.sshPass, password: conn.sshPass,
port: conn.sshPort ? conn.sshPort : 22, port: conn.sshPort ? conn.sshPort : 22,
privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : null, privateKey: conn.sshKey ? fs.readFileSync(conn.sshKey).toString() : undefined,
passphrase: conn.sshPassphrase, passphrase: conn.sshPassphrase,
keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : null keepaliveInterval: conn.sshKeepAliveInterval ? conn.sshKeepAliveInterval*1000 : undefined
}; };
} }
@ -90,11 +90,12 @@ export default (connections: Record<string, antares.Client>) => {
return { status: 'success' }; return { status: 'success' };
} }
catch (err) { catch (error) {
clearInterval(abortChecker); clearInterval(abortChecker);
if (error instanceof AggregateError)
if (!isLocalAborted) throw new Error(error.errors.reduce((acc, curr) => acc +' | '+ curr.message, ''));
return { status: 'error', response: err.toString() }; else if (!isLocalAborted)
return { status: 'error', response: error.toString() };
else else
return { status: 'abort', response: 'Connection aborted' }; return { status: 'abort', response: 'Connection aborted' };
} }

View File

@ -173,7 +173,7 @@ export class MySQLClient extends BaseClient {
remotePort: this._params.port remotePort: this._params.port
}); });
dbConfig.host = (this._ssh.config as SSHConfig[] & { host: string }).host; dbConfig.host = this._ssh.config[0].host;
dbConfig.port = tunnel.localPort; dbConfig.port = tunnel.localPort;
} }
catch (err) { catch (err) {
@ -302,6 +302,8 @@ export class MySQLClient extends BaseClient {
await this.connect(); await this.connect();
return this.getConnection(args, true); return this.getConnection(args, true);
} }
else if (error instanceof AggregateError)
throw new Error(error.errors.reduce((acc, curr) => acc +' | '+ curr.message, ''));
else else
throw new Error(error.message); throw new Error(error.message);
} }

View File

@ -179,7 +179,7 @@ export class PostgreSQLClient extends BaseClient {
remotePort: this._params.port remotePort: this._params.port
}); });
dbConfig.host = (this._ssh.config as SSHConfig[] & { host: string }).host; dbConfig.host = this._ssh.config[0].host;
dbConfig.port = tunnel.localPort; dbConfig.port = tunnel.localPort;
} }
catch (err) { catch (err) {

View File

@ -132,10 +132,20 @@ app.on('ready', async () => {
// mainWindow.webContents.openDevTools(); // mainWindow.webContents.openDevTools();
process.on('uncaughtException', error => { process.on('uncaughtException', error => {
if (error instanceof AggregateError) {
for (const e of error.errors)
mainWindow.webContents.send('unhandled-exception', e);
}
else
mainWindow.webContents.send('unhandled-exception', error); mainWindow.webContents.send('unhandled-exception', error);
}); });
process.on('unhandledRejection', error => { process.on('unhandledRejection', error => {
if (error instanceof AggregateError) {
for (const e of error.errors)
mainWindow.webContents.send('unhandled-exception', e);
}
else
mainWindow.webContents.send('unhandled-exception', error); mainWindow.webContents.send('unhandled-exception', error);
}); });
}); });