Node Azure Web App中的自定义错误消息

时间:2015-07-14 20:43:08

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

遇到一个有趣的问题,一个运行Node with IIS的Azure Web App并想分享,因为我无法找到它的信息。

问题:

我的自定义错误消息并没有在我的生产应用程序上显示给客户端,但在本地发布时却很好。

快速举例:

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.'});
    }
    // ...
});

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

1 个答案:

答案 0 :(得分:8)

解决方案!

web.config文件中,在<system.webServer> ... </system.webServer>

之间添加此行

<httpErrors existingResponse="PassThrough" />

希望没有其他人像我一样打击这个问题。我确定这是一个混合使用不正确的谷歌搜索和缺乏经验的IIS,但我从来没有真正在网上找到答案,我偶然发现了几个链接导致我IIS error handling page

希望这有助于其他人!如果你正在运行IIS网络应用程序,那么该文档中有很多好的信息,我强烈建议你阅读它。