sequelize .authenticate() .then(err => logger.debug('Connection has been established successfully.')) .catch(err => { logger.error('Unable to connect to the database.', err); return null; });
async getFileBuffer(p) { const abs = path.resolve(this.path, p); try { const res = await fs.readFile(abs); return res; } catch (e) { logger.error("[%s] File %s could not be retrieved", this.constructor.name, p); throw e; } }
router.get('/', async (req, res) => { const memoryStorage = req.app.get('memoryStorage'); const services = await new Status(memoryStorage).run(); const failedServices = services.filter(s => s.status !== 'WORKING'); let statusCode = 200; for (const failedService of failedServices) { statusCode = 500; log.error(failedService.message); } res.status(statusCode).json({ services }); });
ipcMain.on(signals.request(signals.CONFIG.READ_IS_USE_DEFAULT), (event, arg) => { sqlodm.prefs.findOne(arg.query).then( result => { result = Object.assign({}, result.toJSON()); event.sender.send(signals.response(signals.CONFIG.READ_IS_USE_DEFAULT), result); }, error => { logger.error(`[${signals.CONFIG.READ_IS_USE_DEFAULT}]. Error: `, error); event.sender.send(signals.response(signals.GENERAL.ERROR), error.toString()); } ); });
jwt.verify(token, config.jwtSecret, (err, decoded) => { if (err) { logger.error(err); return callback(err); } return callback(null, decoded.sub); })
function openUrlInDefaultBrowser (url) { sqlodm.application.findOne({is_default: true}).then( application => { open2(url, application.identifier, '-b'); }, error => { logger.error('[open-url] Failed to get default browser to use. Error: ', error); createSecondaryWindow(url); } ); }
const connectWithRetry = function () { return mongoose.connect(process.env.MONGODB_URL, options, (err) => { if (err) { logger.error("Failed to connect to mongo on startup - retrying in 5 sec", err); setTimeout(connectWithRetry, 5000); } }); }
sendMessage(exchange, key, message) { return this.handler .then(connection => connection.createChannel()) .then(channel => channel.assertExchange(exchange, 'topic', { durable: true }) .then(() => channel.publish(exchange, key, new Buffer(JSON.stringify(message)))) .then(() => logger.debug('Sent message :', message)) .then(() => channel.close()) ) .catch(logger.error); }
ipcMain.on(signals.request(signals.APPLICATION.READ_ONE), (event, arg) => { sqlodm.application.findOne(arg.query, arg.options).then( result => { event.sender.send(signals.response(signals.APPLICATION.READ_ONE), result); }, error => { logger.error(`[${signals.APPLICATION.READ_ONE}] Error: `, error); event.sender.send(signals.response(signals.GENERAL.ERROR), error.toString()); } ); });
redis.createClient({ host: redis_host ,port: redis_port ,password:redis_pwd ,detect_buffers: true }) .on('error', function (err) { logger.error(redis_host + ":" + redis_port + " " + err); }) .on('connect', function () { logger.debug('Redis connected ' + redis_host + ":" + redis_port); })
router.get('/', async (req, res) => { const memoryStorage = req.app.get('memoryStorage'); try { await memoryStorage.ping(); res.send('WORKING'); } catch (err) { log.error(err); res.status(500).send(`Error: ${err.message}`); } });
// When the connection is disconnected mongoose.connection.on("disconnected", () => { logger.error("Mongoose default connection disconnected"); // connectWithRetry(); });
// Synchronizing any model changes with database. sequelize.sync() .then(function() { winston.info("Database synchronized"); }).catch(function(err) { winston.error("An error occured: %j", err); });
sendMessage(exchange, key, message) { return this.handler .then(connection => connection.createChannel()) .then(channel => channel.assertExchange(exchange, 'topic', { durable: true }) .then(() => channel.publish(exchange, key, new Buffer(JSON.stringify(message)))) .then(() => logger.debug('Sent message :', message)) .then(() => channel.close()) ) .catch(logger.error); }