【发布时间】:2018-06-01 08:15:18
【问题描述】:
我开发了一个与 FTP 服务器交互的 Node.js/Express.js 应用程序,问题是如果服务器离线,应用程序会崩溃,因为我找不到处理 ETIMEDOUT 异常的方法。顺便说一下,我用于 FTP 的模块是 jsftp。
发生这种情况的代码部分如下所示:
router.post("/", upload, function(req, res, next) {
try {
ftp.auth(ftp.user, ftp.pass, function(error) {
if(error) {
res.status("500");
res.end("Error: Couldn't authenticate into the FTP server.");
console.log(error);
} else { // Authenticated successfully into the FTP server
/* some code here */
}
});
} catch(error) { // Probably timeout error
res.status("500");
res.end("Internal Server Error");
console.log(error);
}
});
我尝试将.on('error', function(e) { /* my code here */ } 附加到 router.post 函数,但随后我得到TypeError: router.post(...).on is not a function。
有人有什么建议吗?我很感激。
【问题讨论】:
标签: javascript node.js express