【发布时间】:2016-12-29 03:57:37
【问题描述】:
我正在使用 Node.js Express 创建一些 HTTP REST API。 我有调用返回 Promise 的下划线 service 的方法,如下所示:
function getAllApps(request, response) {
appService.getAllApps(request.query.$expand).then(function (apps) {
response.status(200).send(apps);
})
}
我将方法映射如下:
var api = express.app;
api.get('/apps', getAllApps);
现在,我介绍了如下错误处理:
function getAllApps(request, response) {
appService.getApps(request.query.$expand).then(function (apps) {
response.status(200).send(apps);
})
.catch(function (err) {
console.error('Error occurred in Apps Api: ' + err);
response.status(400).send(err);
});
}
除了遇到错误时,它按预期工作,我在控制台中得到完整的错误堆栈,如下所示:
Express is listening on 127.0.0.1:3000
Web Api ready
Error occurred in Apps Api: Error: Actions is not defined on the model.
但是我的 HTTP 方法返回 400 并且正文是空的,它只包含大括号:
{}
【问题讨论】:
-
你是真的扔,还是
apps是空的? -
.stack是错误 afaik 的不可枚举属性,这意味着它将被send忽略。而且您不希望它被发送给用户? -
@Bergi 完成,道歉
标签: javascript node.js express promise