Unhandled error event while inserting and violating db constrait
I must be doing something wrong but I cannot figure out from the documentation how to prevent node from crashing when an insert fails.
var db = require('massive');
var databaseUrl = process.env.DATABASE_URL || 'postgres://localhost/dev'
db.connect(databaseUrl, function(err, db){
user = {
email: 'mail@examle.com',
crypted_password: 'password',
secret: 'hello',
}
db.users.insert(user).execute(function(err, other){
console.log(err);
});
});
node crashes:
events.js:72 throw er; // Unhandled 'error' event
My insert violates a unique constraint