From 323e3b0b5e3380e21c6b9dbfddef94ab936df163 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 24 Feb 2022 10:50:31 +0100 Subject: [PATCH] optimized error handling and application start --- blinky.js | 19 ++++++++----------- libs/util.js | 7 +------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/blinky.js b/blinky.js index a5da2bb..d434399 100644 --- a/blinky.js +++ b/blinky.js @@ -12,20 +12,17 @@ global.config = process.argv[2] || __dirname + '/config.json'; handleInterrupts(); // start the application -main(); +main() + .catch(exit); // main - let's get this party started async function main() { - try { - const config = await util.fileExists(global.config); - global.config = require(config.path); - global.config.path = config.path; - logger.initialize(); - logger.info(await server.start()); - server.handleRequests(); - } catch (err) { - exit(err); - } + const config = await util.fileExists(global.config); + global.config = require(config.path); + global.config.path = config.path; + logger.initialize(); + logger.info(await server.start()); + server.handleRequests(); } // ... and it all comes crashing down diff --git a/libs/util.js b/libs/util.js index 6e514ff..dd53fce 100644 --- a/libs/util.js +++ b/libs/util.js @@ -5,12 +5,7 @@ async function fileExists(file) { if (file === undefined) { throw new Error('can not check the existence of an undefined file'); } - let path; - try { - path = await resolvePath(file); - } catch (err) { - throw err; - } + let path = await resolvePath(file); return await new Promise((resolve, reject) => { stat(path, (err, stats) => { if (err) {