Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ExpressJs返回空res.json_Json_Node.js_Express - Fatal编程技术网

ExpressJs返回空res.json

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

在并行中间件的“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 see in the console: [Error: 'Some error message']
})
但当我这么做的时候

res.json(400, err);
我得到一个空洞的回答

{} No properties

这是什么原因?

JSON无法将错误字符串化。您需要使用其他内容来发送错误

也许只是
res.send(err.message)
,或者类似的东西