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();
|
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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue