You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug? Yes. I think exposing MongooseServerSelectionError and other custom errors written in Mongoose package should be exported. Why? because then I can do error instanceof MongooseServerSelectionError and It would be much much simpler and secure. It is also helps me to write tests with jest. Test like this
// connect-to-mongodb.config.tsimportmongoosefrom'mongoose';import{serializeError}from'serialize-error';import{logger}from'./winston.config';import{Configs}from'../contracts/types/configs.type';mongoose.Promise=global.Promise;exportletmongooseInstance: typeofmongoose;exportconstconnectToDb=async(config: Configs)=>{try{if(config.nodeEnv==='development'){mongoose.set('debug',true);}mongooseInstance=awaitmongoose.connect(config.db_uri,{useNewUrlParser: true,useUnifiedTopology: true,useFindAndModify: true,useCreateIndex: true,autoReconnect: true,connectTimeoutMS: 100_000,reconnectInterval: 10_000,});logger.info('[conn stat] connected to MongoDb',{meta: {connectionString: config.db_uri,},});}catch(err){letmessage='During connecting to the mongodb an error occurred';if(err.name==='MongooseServerSelectionError'){message='Could not connect to the specified connection string';}logger.error(message,{meta: serializeError(err),});throwerr;}};
// connect-to-mongodb.config.test.tsimport{MongooseServerSelectionError}from'mongoose';import{connectToDb,mongooseInstance,}from'../../src/config/connect-to-mongodb.config';import{Configs}from'../../src/contracts/types/configs.type';test('Test connecting to database',function(){describe('connect to database failed',function(){// @ts-ignoreconstconfigs: Configs={nodeEnv: 'development',db_uri: 'mongodb://user:[email protected]/db-name',};expect(connectToDb(configs)).toThrowError(MongooseServerSelectionError);});});
What is the current behavior? No access to the errors (MongooseServerSelectionError)
What is the expected behavior? Exporting custom errors from the library. I mean I would like to import { MongooseServerSelectionError } from 'mongoose';
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS: 17.3.0
MongooseJS: 5.6.2
MongoDB NodeJS driver: 3.5.1
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug? Yes. I think exposing MongooseServerSelectionError and other custom errors written in Mongoose package should be exported. Why? because then I can do
error instanceof MongooseServerSelectionError
and It would be much much simpler and secure. It is also helps me to write tests with jest. Test like thisWhat is the current behavior? No access to the errors (MongooseServerSelectionError)
What is the expected behavior? Exporting custom errors from the library. I mean I would like to
import { MongooseServerSelectionError } from 'mongoose';
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS: 17.3.0
MongooseJS: 5.6.2
MongoDB NodeJS driver: 3.5.1
The text was updated successfully, but these errors were encountered: