Я использую библиотеку npm ftp: https://www.npmjs.com/package/ftp
Я хочу загрузить файл на FTP-сервер, и я хочу ловить ошибки во время соединения, например, неправильный логин.
Моя функция:
const upload = () => {
try {
const ftpClient = new ftp();
fs.readFile(filePathToUpload, 'utf8', (err, data) => {
const fileValue = data.concat(' Timestamp: ', new Date());
ftpClient.on('ready', () => {
ftpClient.put(fileValue, FILENAME_REMOTE, (err) => {
console.log('PUT FTP');
if (err) {
console.log(err);
}
ftpClient.end();
});
});
try {
console.log('connect upload');
ftpClient.connect(ftpConfig);
} catch (connectionError) {
console.log('Connection Error: ', connectionError);
}
});
} catch (err) {
console.log('ERROR-FTP-Upload: ', err);
}
};
Но я всегда получаю 'ERROR Uncaught Exception', даже если я использую
process.on('uncaughtException', err => console.log(err));
Полный след стека:
{"errorType":"Error","errorMessage":"Login incorrect.","code":530,"stack":["Error: Login incorrect."," at makeError (/var/task/node_modules/ftp/lib/connection.js:1067:13)"," at Parser.<anonymous> (/var/task/node_modules/ftp/lib/connection.js:113:25)"," at Parser.emit (events.js:189:13)"," at Parser.EventEmitter.emit (domain.js:441:20)"," at Parser._write (/var/task/node_modules/ftp/lib/parser.js:59:10)"," at doWrite (_stream_writable.js:410:12)"," at writeOrBuffer (_stream_writable.js:394:5)"," at Parser.Writable.write (_stream_writable.js:294:11)"," at Socket.ondata (/var/task/node_modules/ftp/lib/connection.js:273:20)"," at Socket.emit (events.js:189:13)"]}
Как мне справиться с ошибкой?