diff --git a/lib/ssh.js b/lib/ssh.js index f650413..e905da4 100644 --- a/lib/ssh.js +++ b/lib/ssh.js @@ -1,13 +1,13 @@ var Client = require('ssh2').Client, http = require('http'); -module.exports = function(opt) { +module.exports = function (opt) { var conn = new Client(); var agent = new http.Agent(); - agent.createConnection = function(options, fn) { - conn.once('ready', function() { - conn.exec('docker system dial-stdio', function(err, stream) { + agent.createConnection = function (options, fn) { + conn.once('ready', function () { + conn.exec('docker system dial-stdio', function (err, stream) { if (err) { conn.end(); agent.destroy(); @@ -21,6 +21,8 @@ module.exports = function(opt) { agent.destroy(); }); }); + }).on('error', (err) => { + fn(err); }).connect(opt); conn.once('end', () => agent.destroy());