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();
// 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);
}
}
// ... and it all comes crashing down

View file

@ -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) {