小编Eve*_*ney的帖子

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

偶然发现了一个有趣的问题,一个运行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对象.

iis error-handling azure node.js iisnode

4
推荐指数
1
解决办法
422
查看次数

标签 统计

azure ×1

error-handling ×1

iis ×1

iisnode ×1

node.js ×1