I\'m getting this error:
Unhandled rejection SequelizeUniqueConstraintError: Validation error
How can I fix this?
This is my models/use
The call to User.create()
is returning a Promise.reject()
, but there is no .catch(err)
to handle it. Without catching the error and knowing the input values it's hard to say what the validation error is - the request.body.email
could be too long, etc.
Catch the Promise reject to see the error/validation details
User.create({ name: request.body.email })
.then(function(user) {
// you can now access the newly created user
console.log('success', user.toJSON());
})
.catch(function(err) {
// print the error details
console.log(err, request.body.email);
});
Update, since it's 2019 and you can use async/await
try {
const user = await User.create({ name: request.body.email });
// you can now access the newly created user
console.log('success', user.toJSON());
} catch (err) {
// print the error details
console.log(err, request.body.email);
}