Skip to content

Commit

Permalink
fix: don't show error multiple times when lost connection to SSH tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Nov 20, 2016
1 parent 53a284e commit 2b732bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions client/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import _ from 'lodash';
const actions = {
connect(config) {
return dispatch => {
let sshErrorThrown = false
if (config.ssh) {
dispatch({ type: 'updateConnectStatus', data: 'SSH connecting...' });
const conn = new Client();
Expand All @@ -25,26 +26,26 @@ const actions = {
});
})
.on('error', err => {
sshErrorThrown = true
dispatch({ type: 'disconnect' });
alert(`SSH Error: ${err.message}`);
});

try {
const connectionConfig = {
host: config.sshHost,
port: config.sshPort || 22,
username: config.sshUser
}
if (config.sshKey) {
conn.connect({
host: config.sshHost,
port: config.sshPort || 22,
username: config.sshUser,
conn.connect(Object.assign(connectionConfig, {
privateKey: config.sshKey,
passphrase: config.sshKeyPassphrase
});
}));
} else {
conn.connect({
host: config.sshHost,
port: config.sshPort || 22,
username: config.sshUser,
conn.connect(Object.assign(connectionConfig, {
password: config.sshPassword
});
}));
}
} catch (err) {
dispatch({ type: 'disconnect' });
Expand Down Expand Up @@ -98,7 +99,9 @@ const actions = {
});
redis.once('end', function () {
dispatch({ type: 'disconnect' });
alert('Redis Error: Connection failed');
if (!sshErrorThrown) {
alert('Redis Error: Connection failed');
}
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"redux-thunk": "^1.0.0",
"reselect": "^2.0.0",
"sortablejs": "^1.4.1",
"ssh2": "^0.4.12",
"ssh2": "^0.5.4",
"url-loader": "^0.5.7"
},
"devDependencies": {
Expand Down

0 comments on commit 2b732bd

Please sign in to comment.