I started using promises, I use Node.js Mango (from mongoose) and bluebird .. The problem I am facing is for some reason when I associate a mongoose call with functions that return promises (I assume this is the right way return and chain), I get:
typeError: Object #<Promise> has no method 'fail'
If I change the error to catch, I get the same problem:
typeError: Object #<Promise> has no method 'catch'
I am using a function template (null, function) that definitely fails and gets caught. However, catch / fail is more readable. Any clue why I am getting this and how should I solve this problem?
Here is an example code block.
User.findOne({ 'email' : user_email }).exec() }).then (promisedTransformUserSchemaToFrontendObjectWithProjectMapping) .then (function (feUser) { return new Promise(function (resolve, reject) { res.json(feUser); return resolve(feUser); }); }).fail/catch (function (err) { console.log(err); sendError(res,"failed to get user",err); });
And here is the stacktrace:
TypeError: Object #<Promise> has no method 'catch' at module.exports.app.put.User.update.email (app\controllers\router.js:165:16) at callbacks (node_modules\express\lib\router\index.js:164:37) at isLoggedIn (app\controllers\router.js:741:10) at callbacks (node_modules\express\lib\router\index.js:164:37) at param (node_modules\express\lib\router\index.js:138:11) at param (node_modules\express\lib\router\index.js:135:11) at pass (node_modules\express\lib\router\index.js:145:5) at Router._dispatch (node_modules\express\lib\router\index.js:173:5) at Object.router (node_modules\express\lib\router\index.js:33:10) at next (node_modules\express\node_modules\connect\lib\proto.js:193:15)
Dory zidon
source share