Model.update(...).catch is undefined
See original GitHub issueConsider the following:
Subscription.update({
_id: { $not: subscription._id },
startDate: { $lt: today },
endDate: { $gt: newEndDate }
}, {
$set: { endDate: newEndDate }
}).catch(errorHandler);
This complains that Subscription.update(...).catch
is undefined.
Whereas calling it after a save()
operation on an item works fine:
user.save().catch(errorHandler);
Also note that I am using Bluebird promises:
mongoose.Promise = require('bluebird');
Mongoose version is 4.4.19.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
store for model is undefined - javascript - Stack Overflow
The server returns the data (I do see this using fiddler) but I always get the error Unable to set property 'store' of...
Read more >Async/Await Error Handling - Beginner JavaScript - Wes Bos
We will talk about error handling strategies for async await in this lesson. Because there is no .then() that we are chaining on...
Read more >Handling those unhandled promise rejections with JS async ...
One of your await ed functions fails (i.e. rejects a promise); You get the error. Another possibility is that you know you need...
Read more >TypeError: Cannot read property 'listeners' of undefined #7342
I am getting an error ''TypeError: Cannot read property 'listeners' of undefined" while updating an object through custom method defin...
Read more >throw - JavaScript - MDN Web Docs - Mozilla
The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, I think that’s maybe more of a personal opinion 😃
I don’t find it trivial at all, and there are many use cases for me to only use
.catch
and not have a.then
, for example when doing some background updating of data which doesn’t need to send back a response, but does need error handling in case it goes wrong.I find it much cleaner to write
.catch(doSomething)
than something like.then(null, doSomething)
, as it makes it easier to distinguish and separate success handlers and failure handlers and makes the code easier to read. I findthen...catch
pretty much analogous to atry...catch
.Also, from my usage experience it has been around for quite a while now and most promise libraries implement the method, as well as
.finally()
, which in my opinion is also a must have to avoid code duplication in certain circumstances.If you’d want me to make a PR for this let me know, I’ll be happy to look into it.
Thanks, I’ll try to look into it this week 😃