【发布时间】:2021-11-03 17:40:44
【问题描述】:
import {check, validationResult} from 'express-validator';
export const validate = (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
throw new Error(errors.array());
}
next();
};
router.post(
'/register',
[
check('first_name').exists(),
check('last_name').exists(),
check('username').exists(),
],
validate,
(req, res) => {
return res.json({status: 'success', message: 'Ok'});
},
);
express 验证器在控制台打印正确时返回 500 [object Object]
[
{
value: undefined,
msg: 'Invalid value',
param: 'last_name',
location: 'body'
},
{
value: undefined,
msg: 'Invalid value',
param: 'username',
location: 'body'
}
]
我们如何解决这个问题,请指导它应该将收到的内容打印到控制台中
【问题讨论】:
标签: node.js express express-validator