function isIntInRange(start, end, val) { return end > start && _.inRange(val, start, end); }
function isInstInRange(start, end, val) { return _.isDate(val) && end > start && _.inRange(val, start, end); }
displayNetworkHistory(input) { if (_.isEmpty(input)) { _.each(this.networkHistory, (item, index) => { console.log(`#${index} ${item.request.method} ${item.request.uri.pathname}`); }); return; } var index = Number.parseInt(input, 10); if (Number.isNaN(index) || !_.inRange(index, 0, this.networkHistory.length)) { logger.error('Invalid index.'); return; } var item = this.networkHistory[index]; console.log(chalk.bold.green(`Network history (#${index}):`)); console.log(item.toJSON()); }
function makeHandler(svc, handlerItem) { svc.logger.debug('makeHandler:', handlerItem); return async function (action, params, respond) { svc.logger.info(` => Client '${this.id}' call '${action}'`); if (svc.settings.logRequestParams && svc.settings.logRequestParams in svc.logger) svc.logger[svc.settings.logRequestParams](" Params:", params); try { if (_.isFunction(params)) { respond = params; params = null; } let res = await svc.actions.call({ socket: this, action, params, handlerItem }); svc.logger.info(` <= ${chalk.green.bold('Success')} ${action}`); if (_.isFunction(respond)) respond(null, res); } catch (err) { if (svc.settings.log4XXResponses || err && !_.inRange(err.code, 400, 500)) { svc.logger.error(" Request error!", err.name, ":", err.message, "\n", err.stack, "\nData:", err.data); } if (_.isFunction(respond)) svc.socketOnError(err, respond); } }; }
function makeHandler(svc, handlerItem){ svc.logger.debug('makeHandler:', handlerItem) return async function(action, params, respond){ svc.logger.info(` => Client '${this.id}' call '${action}'`); if (svc.settings.logRequestParams && svc.settings.logRequestParams in svc.logger) svc.logger[svc.settings.logRequestParams](" Params:", params); try{ if(_.isFunction(params)){ respond = params params = null } let res = await svc.actions.call({socket:this, action, params, handlerItem}) svc.logger.info(` <= ${chalk.green.bold('Success')} ${action}`) if(_.isFunction(respond)) respond(null, res) }catch(err){ if (svc.settings.log4XXResponses || (err && !_.inRange(err.code, 400, 500))) { svc.logger.error(" Request error!", err.name, ":", err.message, "\n", err.stack, "\nData:", err.data); } if(_.isFunction(respond)) svc.socketOnError(err, respond) } } }