我正在使用winston记录器。我发现尝试提供路径不准确的文件时,我看到错误TreeView {
id: view
model: fileSystemModel
...
TableViewColumn {
role: "checkRole"
delegate: Component {
CheckBox {
id: mycbx
checked: styleData.value
onCheckedChanged: view.model.setData(styleData.index, checked, 10)
}
}
}
...
。这是预期的行为。但是,错误不会通过winston记录(因此不会被推到我的松弛webhook)。它会被记录到节点控制台,但我的winston记录器不会将其记录下来。我尝试在try / catch中包装Error: ENOENT: no such file or directory
,但这也不起作用。
.sendFile()
答案 0 :(得分:3)
我需要使用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,
},
};
res.status(200).sendFile(filePath, sendFileOptions, (error) => {
if (error) {
logger.error(error);
}
});
};
module.exports = serveFile;