【发布时间】: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