// private functions function generateFilename(image) { try { // sometime at intial bootup, seeding is not available. // crypto sync version is comparable to async in perf as bytes are much smaller. return crypto.randomBytes(12).toString('hex') + image.originalName; } catch(e) { log.warn(e, 'Failed to generate filename via crypto.randomBytes.'); return Date.now() + image.originalName; } }
// catch-all error for routes. router.use((err, req, res, next) => { if(err && err.code === 'LIMIT_FILE_SIZE') { log.warn(err, 'Attempt to access api with greater file size'); return errors.entityTooLarge(res); } else { log.warn({req: req, res: res, err: err}, 'Catch all router error'); return next(); } });
log.warn(err, 'Error into getting url. Route: /dl/:id'); return errors.internalServer(res); })
log.warn({req: req}, 'File with Unsupported media type post'); return errors.unsupportedMediaType(res);
userDao.findByApiKey(hash(key)).then(function (user) { if (user) { // Return the user. logger.debug('User %s authorized.', user.uid) return Promise.resolve(user) } else { // User not found and auto grant access is disabled. logger.warn('API key not found: %s', key) return Promise.reject(new errors.Unauthorized('Bad API key.')) } })
monitor.start().done(function() { if (argv.discover) { var discoveryData = provider.getDiscoveryData(); process.stdout.write(JSON.stringify(discoveryData, null, '\t')); process.exit(0); return; } if (!argv.discover && !argv.monitor) { logger.warn({ event: 'pm2-zabbix#noWork', argv: process.argv }, 'Neither --discover nor --monitor was specified - exiting because we have nothing to do'); process.exit(0); return; } });
function getPackage (pkgname, callback) { manifest.get(pkgname, function (err, stored) { if (err && !err.notFound) { logger.error(err, 'leveldb.get error'); return callback(err); } if (err && err.notFound) { logger.warn({pkgname}, 'not found, returning empty object'); return callback(null, {}); } logger.info({pkgname}, 'found, returning stored package data'); callback(null, stored); }); }
/** * Get container usage. * @param {String} container Container name * @return {Promise} Promise of the container usage */ const usage = function (container) { return files.chdu(container).catch((err) => { logger.warn('Unable to get storage usage of the container: ' + container, err) return Promise.resolve(-1) }) }
blockStartup(shouldBlock, next) { this.blockBooting = (shouldBlock !== false); if (this.blockBooting) { this.log.warn('Server booting is now BLOCKED.'); } else { this.log.info('Server booting is now UNBLOCKED.'); } return next(); }
const halt = async (currentAccountValue) => { if (transactionLock) { return false; } log.warn(`Halt: Market has crashed beyond your critical point of ${config.get('sienaAccount.criticalPoint') * 100}% from ${principle} to ${currentAccountValue}`); // The market has crashed and your capital has eroded. Sell what you can stop trading! if (lastTrade === 'buy') { await sellSecurity(); } log.warn('Halt: Halting any further trades'); allowTrading = false; return true; }
const processResourceEntry = function (zipEntry, doc) { const name = zipEntry.entryName const key = name.substr(name.lastIndexOf('/') + 1) const index = doc.attachments.findIndex(function (item) { return item.key === key }) if (index >= 0) { // Update resource size doc.attachments[index].contentLenght = zipEntry.header.size // Save resource to storage const container = storage.getContainerName(doc.owner, 'documents', doc.id, 'files') return importFile(zipEntry.getData(), container, key) .then(() => { return Promise.resolve(doc) }) } else { logger.warn('File not referenced by meta data: %s', key) return Promise.resolve(doc) } }
suspend(next) { Async.parallel([ callback => { this.modifyConfig({ suspended: 1 }, callback); }, callback => { if (this.status !== Status.OFF) { return this.kill(callback); } return callback(); }, ], err => { if (!err) { this.log.warn('Server has been suspended.'); } return next(err); }); }
Promise.all(readTasks).then(() => { if (buySellPoints.length === 0) { return log.warn('Logs didn\'t contain trade entries'); } log.info(`${Object.keys(buySellPoints).length} trades obtained.`); const buySellPointsString = Object.keys(buySellPoints).sort().map(timestamp => buySellPoints[timestamp]).join('\n'); fs.writeFile('./tradeHistory.txt', buySellPointsString, (err) => { if (err) { return log.err(err); } return log.info('Generated tradeHistory.txt'); }); return true; });
dataBase.init() .then(() => server.start()) .catch(() => { logger.warn('DB not running. Using in memory data'); server.start(); });
initContainer(next) { this.docker = new Docker(this, (err, status) => { if (err && _.startsWith(_.get(err, 'json.message', 'error'), 'No such container')) { this.log.warn('Container was not found. Attempting to recreate it.'); this.rebuild(rebuildErr => { if (rebuildErr && !_.isUndefined(rebuildErr.statusCode)) { if (_.startsWith(_.get(rebuildErr, 'json.message'), 'No such image')) { rebuildErr.code = 'PTDL_IMAGE_MISSING'; // eslint-disable-line return next(rebuildErr); } } return next(rebuildErr); }); } else { if (!err && status) { this.log.info('Daemon detected that the server container is currently running, re-attaching to it now!'); } return next(err); } }); }