Anton
Anton

Reputation: 6033

Bluebird Promise: error is not a function

For some reason that I can't find out, this simple piece of code doesn't work.

new Promise(function (resolve, reject) {
  resolve();
}).then(function() {
  console.log("then: ")
}).error(function(err) {
  console.log("err: ", err)
})

It gives me

Uncaught TypeError: (intermediate value).then(...).error is not a function

If I replace error with catch, it runs fine. I would prefer not to catch though.

What am I missing here?

Upvotes: 1

Views: 2723

Answers (2)

Hod
Hod

Reputation: 2276

This can also happen if you include another package that uses a different promise library.

In my case, I have a Node app that requires Swagger. Swagger uses the Q promise library.

Bluebird and Q are partially compatible. The problem didn't show up until I started using parts of the Bluebird API that Q doesn't have. In particular, Bluebird has "return", whereas Q does not. (Try searching for "bluebird return is not a function" if you want to waste some time.)

There's a project "bluebird-q" designed to allow Bluebird to replace Q.

With Swagger in particular, there's a flag to make Swagger use promises. It might work to promisifyAll Swagger instead of using the usePromise configuration.

Upvotes: 0

jfriend00
jfriend00

Reputation: 707218

Making this comment an answer since it turned out to be the solution...

If .error() does not exist, then you probably aren't using a Bluebird promise since .error() is not part of the Promise standard so you may just have a built-in promise instead of a Bluebird promise.

Check to make sure that Bluebird is properly included in your project.

Upvotes: 5

Related Questions