【问题标题】:Custom Error Messages in Node Azure Web AppNode Azure Web App 中的自定义错误消息
【发布时间】:2015-07-15 04:43:08
【问题描述】:

偶然发现一个使用 IIS 运行节点的 Azure Web 应用程序的有趣问题,并想分享,因为我找不到有关它的信息。

问题:

我的自定义错误消息没有在我的生产应用程序上传递给客户端,但在本地通过就好了。

快速示例:

app.post('/user', function(req, res, next) {
    // Parse out the user data
    // ...
    // Oh no! An error!
    if (invalidData) {
        return res.status(400).json({error: 'Invalid username, must be at least 4 characters.'});
    }
    // ...
});

这是通过我的 Web 应用程序作为标准“400:错误请求...”消息而不是我的自定义错误消息。在客户端上,我尝试执行 JSON.parse(err.responseText).error 不起作用,因为 err.responseText"Bad request..." 字符串而不是我的 JSON 对象。

【问题讨论】:

    标签: node.js azure iis error-handling iisnode


    【解决方案1】:

    解决方案!

    在您的web.config 文件中,在<system.webServer> ... </system.webServer> 之间添加这一行:

    <httpErrors existingResponse="PassThrough" />

    希望没有其他人像我一样遇到这个问题。我确信这是错误的谷歌搜索和 IIS 缺乏经验的混合,但我实际上从未在网上找到答案,我偶然发现了一些链接,这些链接将我带到了 IIS error handling page

    希望这对其他人有帮助!如果您正在运行 IIS Web 应用程序,那么该文档中有大量有用的信息,我强烈建议您通读一遍。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-12
      • 2014-12-09
      • 1970-01-01
      相关资源
      最近更新 更多