Lets say that a user is creating an account, but the inputs aren't valid, so I send the errors to the frontend and return a 409 status code. But when the error is in the server side, I don't want to return a 409 status code, but a 5xx status code. How can I achieve this?
exports.signup = (req, res) => {
try {
//pseudocode
db.createUser(req.user);
res.status(201).send("user created!");
} catch (err) {
const errors = { username: "", password: "" };
//pseudocode
forEach((error) => {
if(validation.error.username) {
errors.username = validation.error.username
} else {
errors.password = validation.error.password
})
res.status(409).json(errors);
}
};