In Sails.js it is possible to use different database connections for models and it is easy to change database (MySQL or MongoDB). The problem arises when I want to display validation errors. These are my codes:
Groups.js model
...
connection: 'MysqlConnection', //or connection: 'MongodbConnection'
attributes: {
id: {
type: 'string',
unique: true
},
name: {
type: 'string',
required: true
},
...
GroupsController.js controller:
...
//add group to database
Groups.create(group, function (err, data) {
if (err) {
console.log(err);
res.send('Error'); // is it possible to send only validation error
return;
} else {
res.send(data);
}
});
...
Should I handle each attribute validation error separately, is it possible to send only validation error?
MySQL returns:
Error (E_VALIDATION) :: 1 attribute is invalid ...
MongoDB returns:
Error (E_UNKNOWN) :: Encountered an unexpected error ...