question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'.then(...).catch' not a function

See original GitHub issue

Hi,

I just encountered this issue while working with promise queries. For example:

users.find({})
  .then(data => {
    res.json(data);
  })
  .catch(err => {
    errors.db(err);
  });

works fine if only the .then(...) is present, but catch gets reported as not being a function.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
oreqizercommented, Sep 11, 2015
users.findOne({
    name: req.params.username
  })
  .then(data => {
    if (!data) {
      let err = new Error();
      err.status = 404;
      return next(err);
    }
    res.json(data);
  }, err => {
    next(err);
  });
//  .error(err => {
//    next(err);
//  });

This works. However, .error(fn) does not work either for me - error gets replaced by users.findOne(...).then(...).error is not a function.

0reactions
mathieudutourcommented, Jun 23, 2016

fixed in #132 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: promise.then(...).then(...).then(...).then(...).catch is ...
It looks like you're using Mongoose, which returns its own Promise, not the ES6 promise which includes a catch function.
Read more >
Promise.prototype.catch() - JavaScript - MDN Web Docs
The catch() method of a Promise object schedules a function to be called when the promise is rejected. It immediately returns an equivalent ......
Read more >
Using .then(), .catch(), .finally() to Handle Errors in Javascript ...
It is common practice to learn the .then() method with Promises. .then takes a callback function and returns another Promise (!) and you...
Read more >
TypeError: then is not a function in JavaScript | bobbyhadz
The "then is not a function" error occurs when the then() method is called on a value that is not a promise. To...
Read more >
Catch is not a function - Odoo
I have this nested functions but it only called the first 2 functions and then skipped the others. Add it is too fast...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found