optimized error handling and application start

This commit is contained in:
Daniel Sommer 2022-02-24 10:50:31 +01:00
parent e7f259b683
commit 323e3b0b5e
2 changed files with 9 additions and 17 deletions

View file

@ -12,20 +12,17 @@ global.config = process.argv[2] || __dirname + '/config.json';
handleInterrupts(); handleInterrupts();
// start the application // start the application
main(); main()
.catch(exit);
// main - let's get this party started // main - let's get this party started
async function main() { async function main() {
try { const config = await util.fileExists(global.config);
const config = await util.fileExists(global.config); global.config = require(config.path);
global.config = require(config.path); global.config.path = config.path;
global.config.path = config.path; logger.initialize();
logger.initialize(); logger.info(await server.start());
logger.info(await server.start()); server.handleRequests();
server.handleRequests();
} catch (err) {
exit(err);
}
} }
// ... and it all comes crashing down // ... and it all comes crashing down

View file

@ -5,12 +5,7 @@ async function fileExists(file) {
if (file === undefined) { if (file === undefined) {
throw new Error('can not check the existence of an undefined file'); throw new Error('can not check the existence of an undefined file');
} }
let path; let path = await resolvePath(file);
try {
path = await resolvePath(file);
} catch (err) {
throw err;
}
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
stat(path, (err, stats) => { stat(path, (err, stats) => {
if (err) { if (err) {