Initial Connection errors are not handled
Closed this issue · 2 comments
abhay27chauhan commented
Is your feature request related to a problem? Please describe.
snippet of you code -
mongoose.connect(dbURI, {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, autoIndex: true, useFindAndModify:false});
mongoose.connection.on('error', function (err) {
console.log('DB connection error: ' + err);
});
read this pls, the error handling part -
https://mongoosejs.com/docs/connections.html#:~:text=If%20initial%20connection%20fails%2C%20Mongoose,after%20initial%20connection%20was%20established.
you have handle two errors -
if promise is rejected -> using the above code i have proposed
error after initial connection is made -> using the event handlers
Describe the solution you'd like
will use try/catch along with async/await for handling the initial connection error.
abhay27chauhan commented
I am a participant of GSSOC21, so please let me know if this is a valid proposal
ADRE9 commented
Go Ahead !