ladjs / mongoose

Mongoose helper for Lad

Home Page:https://lad.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is Говнокод

nook-scheel opened this issue · comments

mongoose/index.js

Lines 58 to 85 in 16eb60b

mongoose._connect = mongoose.connect;
mongoose.connect = (uri, options) => {
uri = uri || mongoose.config.mongo.uri;
options = options || mongoose.config.mongo.options;
return new Promise(async (resolve, reject) => {
try {
await mongoose._connect(uri, options);
// output debug info
mongoose.config.logger.debug('mongo connected');
resolve();
} catch (err) {
mongoose.config._connectionAttempts++;
if (
mongoose.config._connectionAttempts >=
mongoose.config.mongo.options.reconnectTries
)
return reject(err);
mongoose.config.logger.warn(
`attempting to reconnect to mongo in ${
mongoose.config.mongo.options.reconnectInterval
} ms with ${mongoose.config.mongo.options.reconnectTries -
mongoose.config._connectionAttempts} retries remaining`
);
await delay(mongoose.config.mongo.options.reconnectInterval);
resolve(mongoose.connect());
}
});
};

This is not Говнокод

mongoose.connect = async (uri = mongoose.config.mongo.uri, options = mongoose.config.mongo.options) => {
  try {
    await mongoose._connect(uri, options);

    // output debug info
    mongoose.config.logger.debug('mongo connected');

    return;
  } catch (err) {
    mongoose.config._connectionAttempts++;

    if (
      mongoose.config._connectionAttempts >=
      mongoose.config.mongo.options.reconnectTries
    ) {
      throw err;
    }

    mongoose.config.logger.warn(
      `attempting to reconnect to mongo in ${
        mongoose.config.mongo.options.reconnectInterval
      } ms with ${mongoose.config.mongo.options.reconnectTries -
        mongoose.config._connectionAttempts} retries remaining`
    );

    await delay(mongoose.config.mongo.options.reconnectInterval);

    return mongoose.connect();
  }
};

Can you please translate in English?