Problem: When I am using Postman
, I was trying to POST
a data but it is still returning 200
even if the value was already been in a server.
This is my code
// Create and Save a new Note
exports.create = (req, res) => {
// Validate request
if(!req.body.content) {
return res.status(400).send({
message: "Note content can not be empty"
});
}
if (req.body.content.length < 5) {
return res.status(422).send({
message: "Note cannot be less than 5 characters"
});
}
if (req.body.title.length < 5) {
return res.status(422).send({
message: "Title cannot be less than 5 characters"
})
}
// Create a Note
const note = new Note({
title: req.body.title || "Untitled Note",
content: req.body.content
});
// Save Note in the database
note.save()
.then(data => {
res.send(data);
}).catch(err => {
res.status(500).send({
message: err.message || "Some error occurred while creating the Note."
});
});
};
Expected output: I should be getting a error message on postman that the value was already been posted. Hence you cannot create another record if that value is already been added.