var saveUser = function(name, profile){
assert(typeof name === 'string')
assert(profile instanceof Profile)
return new bluebird.Promise(function(resolve, reject){
// async code saving user to DB
})
}
Or
var saveUser = function(name, profile){
return new bluebird.Promise(function(resolve, reject){
try {
assert(typeof name === 'string')
assert(profile instanceof Profile)
} catch(err){
return reject(err)
}
// async code saving user to DB
})
}
- Which way is better?
- It is good idea to catch validation errors and throw custom
ValidationError
instead?