optimized error handling and application start
This commit is contained in:
parent
e7f259b683
commit
323e3b0b5e
2 changed files with 9 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue