【发布时间】:2018-10-15 06:45:01
【问题描述】:
我正在使用带有 winston 记录器的 express。当 express 尝试提供路径不准确的文件时,我看到错误 Error: ENOENT: no such file or directory。这是预期的行为。但是,错误不会通过 winston 记录(因此不会被推送到我的 slack webhook)。它被记录到节点控制台,但没有被我的 winston 记录器拾取。我尝试将 .sendFile() 包装在 try/catch 中,但这也不起作用。
const logger = require('winston');
const serveFile = ({ filePath, fileType }, res) => {
logger.verbose(`serving file: ${filePath}`);
const sendFileOptions = {
headers: {
'X-Content-Type-Options': 'nosniff',
'Content-Type' : fileType,
},
};
try {
res.status(200).sendFile(filePath, sendFileOptions);
} catch (error) {
logger.error(error);
}
};
module.exports = serveFile;
【问题讨论】:
标签: javascript node.js express winston sendfile