I have a couple very basic setup steps before I call my promisified functions and I am considering wrapping them in a try/catch block because that seems the simplest way. However, it seems a little dirty to me.
Should I instead make a function that returns a Promise, even if it is very simple? Here is an example.
try
thingyId = req.params.id # here I am 99.999% sure that params is defined,
# but if for some bizarre reason it's not, I'd like to handle that error
# instead of breaking the whole program
catch
console.log "error: " + e
# do normal promisified functions
or should I write this as
setThingyId = (req) ->
return new Promise (resolve, reject) !->
if req.hasOwnProperty "params"
resolve req.params.id
else
reject new Error "no params"
setThingyId(req)
.then (deviceId) ->
# other promisified functions