In my user model I have:
module.exports = {
attributes: {
username: {
type: 'string',
unique: true,
required: true,
minLength: 5,
maxLength: 15,
alphanumeric: true
}
}
}
Now when I try and insert a duplicate username I get the following message:
Logic error in mySQL ORM.
{ [Error: ER_DUP_ENTRY: Duplicate entry 'username' for key 'username'] code: 'ER _DUP_ENTRY', index: 0 }
Now my question is how do I catch this error so I can display a custom error message to the user? My create is like so:
User.create({
username: "username"
}).done(function(err, data){
if(err){
//the error isn't here
}
});