Skip to content

Commit

Permalink
Prevents crash when connecting to FTP
Browse files Browse the repository at this point in the history
Catch FTP connection errors so it won't break the server.
  • Loading branch information
JbIPS committed Mar 25, 2018
1 parent 1168102 commit d5af2f7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/unifile-ftp.js
Expand Up @@ -159,6 +159,9 @@ class FtpConnector {

return new Promise((resolve, reject) => {
const client = new Ftp(ftpConf);
client.on('error', (err) => {
reject(err);
});
// Successful connection
client.once('connect', () => {
client.auth(ftpConf.user, ftpConf.password, (err) => {
Expand All @@ -168,7 +171,10 @@ class FtpConnector {
});
})
.catch((err) => {
throw new UnifileError(UnifileError.EACCES, 'Invalid credentials');
if(err.code === 'ETIMEDOUT')
throw new UnifileError(UnifileError.EIO, 'Unable to reach server');
else
throw new UnifileError(UnifileError.EACCES, 'Invalid credentials');
})
.then(() => {
Object.assign(session, ftpConf);
Expand Down

0 comments on commit d5af2f7

Please sign in to comment.