Simple Chat Room in NodeJS, expressJS and mongoDB in Docker Swarm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

5 years ago
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./mongooseError');
const allServersUnknown = require('../helpers/topology/allServersUnknown');
const isAtlas = require('../helpers/topology/isAtlas');
/*!
* ignore
*/
const atlasMessage = 'Could not connect to any servers in your MongoDB Atlas cluster. ' +
'One common reason is that you\'re trying to access the database from ' +
'an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas ' +
'cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/';
class MongooseServerSelectionError extends MongooseError {
/**
* MongooseServerSelectionError constructor
*
* @api private
*/
assimilateError(err) {
const reason = err.reason;
// Special message for a case that is likely due to IP whitelisting issues.
const isAtlasWhitelistError = isAtlas(reason) &&
allServersUnknown(reason) &&
err.message.indexOf('bad auth') === -1;
this.message = isAtlasWhitelistError ?
atlasMessage :
err.message;
for (const key in err) {
if (key !== 'name') {
this[key] = err[key];
}
}
return this;
}
}
Object.defineProperty(MongooseServerSelectionError.prototype, 'name', {
value: 'MongooseServerSelectionError'
});
module.exports = MongooseServerSelectionError;