From 7f700d42c8f71df94bbd8f72ddec10f6198babd7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 23 Apr 2017 15:40:13 +0900 Subject: [PATCH] Refactoring --- src/index.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index 15e17a16a3..4dda0e9df7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,12 +54,8 @@ async function masterMain() { config = await init(); } catch (e) { console.error(e); - process.exit(1); - } - - if (config == null) { Logger.error(chalk.red('Fatal error occurred during initializing :(')); - process.exit(); + process.exit(1); } Logger.info(chalk.green('Successfully initialized :)')); @@ -70,7 +66,7 @@ async function masterMain() { } spawnWorkers(() => { - Logger.info(chalk.bold.green(`Now listening on port ${loadConfig().port}`)); + Logger.info(chalk.bold.green(`Now listening on port ${config.port}`)); }); } @@ -96,8 +92,7 @@ async function init(): Promise { let configLogger = new Logger('Config'); if (!fs.existsSync(configPath)) { - configLogger.error('Configuration not found'); - return null; + throw 'Configuration not found'; } const config = loadConfig(); @@ -106,15 +101,13 @@ async function init(): Promise { configLogger.info(`maintainer: ${config.maintainer}`); if (process.platform === 'linux' && !isRoot() && config.port < 1024) { - Logger.error('You need root privileges to listen on port below 1024 on Linux'); - return null; + throw 'You need root privileges to listen on port below 1024 on Linux'; } // Check if a port is being used /* https://github.com/stdarg/tcp-port-used/issues/3 if (await portUsed.check(config.port)) { - Logger.error(`Port ${config.port} is already used`); - return null; + throw `Port ${config.port} is already used`; } */ @@ -125,8 +118,7 @@ async function init(): Promise { mongoDBLogger.info('Successfully connected'); db.close(); } catch (e) { - mongoDBLogger.error(e); - return null; + throw e; } return config;