Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why connect() does not return a promise ? #3622

Closed
davibe opened this issue Nov 27, 2015 · 7 comments
Closed

why connect() does not return a promise ? #3622

davibe opened this issue Nov 27, 2015 · 7 comments
Milestone

Comments

@davibe
Copy link

davibe commented Nov 27, 2015

Since most of the api is promised, i was wondering why connect() function is not.

It looks bad (example: https://gist.github.com/davibe/8986a865a96005fa2467)

@vkarpov15 vkarpov15 added this to the 4.3 milestone Nov 28, 2015
@vkarpov15
Copy link
Collaborator

You're right, worth adding this.

@davibe
Copy link
Author

davibe commented Nov 29, 2015

probably the same goes for disconnect()

@Jokero
Copy link
Contributor

Jokero commented Dec 1, 2015

+1

2 similar comments
@xpepermint
Copy link

+1

@bsonntag
Copy link

bsonntag commented Jan 6, 2016

+1

vkarpov15 added a commit that referenced this issue Jan 24, 2016
make connect/open/openSet/disconnect return a promise, fixes #3622
@Jokero
Copy link
Contributor

Jokero commented May 6, 2016

@vkarpov15 How to handle mongoose.connect() error in catch handler? I want to use application initialization chain but can't do that because mongoose.connect() does not return rejected promise.
It returns rejected promise only if I specify callback, but it's not a perfect solution.

Example:

mongoose.connect('mongodb://127.0.0.2/test')
    .then(() => {
        return server.start();
    })
    .catch(err => { // <---- we will not be here...
        console.error('App starting error:', err.stack);
        process.exit(1);
    });

Workaround:

mongoose.connect('mongodb://127.0.0.2/test', function() { /* dummy function */ })
    .then(() => {
        return server.start();
    })
    .catch(err => { // mongoose connection error will be handled here
        console.error('App starting error:', err.stack);
        process.exit(1);
    });

@vkarpov15
Copy link
Collaborator

@Jokero that's odd. Can you open up a separate issue for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants