ExpressJs返回空res.json
在并行中间件的“pre”中验证mongoose模式时ExpressJs返回空res.json,json,node.js,express,Json,Node.js,Express,在并行中间件的“pre”中验证mongoose模式时 schema.pre('save', true, function (next, done) { if(...) { next(new Error('Some error message')); } next(); }); 我返回一个错误,它在回调函数中可用: model.save({},{}, function(err) { res.json(400, err); console.log(err)// I s
schema.pre('save', true, function (next, done) {
if(...) {
next(new Error('Some error message'));
}
next();
});
我返回一个错误,它在回调函数中可用:
model.save({},{}, function(err) {
res.json(400, err);
console.log(err)// I see in the console: [Error: 'Some error message']
})
但当我这么做的时候
res.json(400, err);
我得到一个空洞的回答
{} No properties
这是什么原因?JSON无法将错误字符串化。您需要使用其他内容来发送错误 也许只是
res.send(err.message)
,或者类似的东西