Eve*_*ney 4 iis error-handling azure node.js 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.'});
}
// ...
});
Run Code Online (Sandbox Code Playgroud)
这是通过我的Web应用程序作为标准的"400:错误请求..."消息,而不是我的自定义错误消息.在客户端,我试图做JSON.parse(err.responseText).error这是无法正常运转的err.responseText是"Bad request..."字符串,而不是我的JSON对象.
| 归档时间: |
|
| 查看次数: |
422 次 |
| 最近记录: |