我想捕获 api 文件夹中的错误。
但是,除非使用标准快速路由声明的任何处理程序触发了错误,否则快速错误处理中间件不会捕获任何内容 app.get(someroute,handler)
对此有什么建议吗?
提前致谢。
app.js
mobile.api.import('./api');
mobile.tables.initialize()
.then(function () {
app.use(mobile); // Register the Azure Mobile Apps middleware
app.listen(process.env.PORT || 3000); // Listen for requests
})
.then(function(){
if (process.env.NODE_ENV == 'production'){
///handle errors on prod
app.use(function(err, req, res, next) {
console.log('error catch - here');
res.statusCode = 500;
res.end();
});
}
});
api/testing.js
module.exports = {
"get": function (req, res, next) {
throw new Error('this is error');
}
};
最佳答案
你的理解是正确的。适用于 Azure 移动应用的 Node.js SDK 使用 Express,因此它使用相同的语义。 (旁注 - 我们简要讨论了不实现自定义 API 工具。它实际上是为了支持 Azure 门户的门户内编辑功能)。
一个更好的问题(不是这个论坛的问题,它是关于回答编程问题的)是你想要发生什么?在 https://github.com/Azure/azure-mobile-apps-node 上提交问题存储库,以便我们可以进行讨论。
关于javascript - azure-mobile-apps-node 中的错误中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43533424/