【发布时间】:2022-01-31 04:25:35
【问题描述】:
*请任何人帮助,如果名称存在于 NodeJS express 中,我会尽量避免该请求 *
这是我的代码
/* Post new person to persons */
app.post("/api/persons/", (req, res) => {
const schema = {
name: Joi.string().alphanum().min(3).max(30).required(),
number: Joi.string().min(9).max(30).required(),
};
const { error } = validateFunction(req.body);
const { body } = req;
const reqValue = persons.some(
(person) => person.name.toLowerCase() === body.name.toLowerCase()
);
if (error) return res.status(400).send(error.details[0].message);
else if (reqValue)
return res.status(409).send(`${body.name} is already exist`);
else {
const person = {
id: persons.length + 1,
name: req.body.name,
number: req.body.number,
};
【问题讨论】:
-
你需要描述你的问题是什么
-
httpstatuses.com/409 描述了错误的含义
标签: javascript node.js express