javascript - azure-mobile-apps-node 中的错误中间件

标签 javascript node.js azure error-handling azure-mobile-services

我想捕获 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/

相关文章:

javascript - Typescript 和 Jquery 语法问题

javascript - 与 Flot 的多栏聊天

javascript - 为什么语句 if ( !condition ) { console.log(condition) } 显示 true

javascript - 由于 URI 错误,无法连接到 MongoDB

javascript - 使用 java servlet 的 ajax 多输入表单验证不起作用。 Ajax不显示错误

javascript - Web 服务器上的 NodeJS 应用程序导致 fork 炸弹 - bash : fork: retry: No child processes

node.js - Angular2 通知与路由器导航链接

azure - Terraform - 将 for_each 与元组内的字符串列表一起使用

node.js - "Application has thrown an uncaught exception and is terminated: Error: listen EACCES 0.0.0.0:80"

订阅的 Azure ServiceBus SAS key