aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2020-04-27 02:41:40 -0400
committerKevin J Hoerr <kjhoerr@protonmail.com>2020-04-27 02:41:40 -0400
commit8b70567b9446d5791fac38f48cd1308a043dbd88 (patch)
tree909625735d2b013f77110197949551db0eadbead /src
parentddecabba54eb24ab4ac07a67621f805d3ad9e2ce (diff)
downloadao-coverage-8b70567b9446d5791fac38f48cd1308a043dbd88.tar.gz
ao-coverage-8b70567b9446d5791fac38f48cd1308a043dbd88.tar.bz2
ao-coverage-8b70567b9446d5791fac38f48cd1308a043dbd88.zip
Handle promise errors in handleStartup
Diffstat (limited to 'src')
-rw-r--r--src/util/config.ts77
1 files changed, 42 insertions, 35 deletions
diff --git a/src/util/config.ts b/src/util/config.ts
index b3a1ead..d2ad130 100644
--- a/src/util/config.ts
+++ b/src/util/config.ts
@@ -37,7 +37,7 @@ export const persistTemplate = async (input: Template): Promise<void> => {
process.exit(1);
}
// if the output file exists, then we are fine with continuing without
- logger.warning(
+ logger.warn(
"Could not generate '%s' from template file, but file already exists: %s",
input.outputFile,
err1
@@ -50,43 +50,50 @@ const TARGET_URL = process.env.TARGET_URL ?? "http://localhost:3000";
const HOST_DIR = configOrError("HOST_DIR");
export const handleStartup = async (): Promise<MongoClient> => {
- await fs.promises.access(HOST_DIR, fs.constants.R_OK | fs.constants.W_OK);
- if (!path.isAbsolute(HOST_DIR)) {
- logger.error("HOST_DIR must be an absolute path");
- process.exit(1);
- }
-
- const mongo = await new MongoClient(MONGO_URI, { useUnifiedTopology: true })
- .connect()
- .catch((err: MongoError) => {
- logger.error(err.message ?? "Unable to connect to database");
+ try {
+ await fs.promises.access(HOST_DIR, fs.constants.R_OK | fs.constants.W_OK);
+ if (!path.isAbsolute(HOST_DIR)) {
+ logger.error("HOST_DIR must be an absolute path");
process.exit(1);
- });
+ }
+
+ const mongo = await new MongoClient(MONGO_URI, { useUnifiedTopology: true })
+ .connect()
+ .catch((err: MongoError) => {
+ logger.error(err.message ?? "Unable to connect to database");
+ process.exit(1);
+ });
- await persistTemplate({
- inputFile: path.join(
- __dirname,
- "..",
- "public",
- "templates",
- "bash.template"
- ),
- outputFile: path.join(HOST_DIR, "bash"),
- context: { TARGET_URL }
- } as Template);
- await persistTemplate({
- inputFile: path.join(
- __dirname,
- "..",
- "public",
- "templates",
- "index.html.template"
- ),
- outputFile: path.join(HOST_DIR, "index.html"),
- context: { TARGET_URL }
- } as Template);
+ await persistTemplate({
+ inputFile: path.join(
+ __dirname,
+ "..",
+ "..",
+ "public",
+ "templates",
+ "bash.template"
+ ),
+ outputFile: path.join(HOST_DIR, "bash"),
+ context: { TARGET_URL }
+ } as Template);
+ await persistTemplate({
+ inputFile: path.join(
+ __dirname,
+ "..",
+ "..",
+ "public",
+ "templates",
+ "index.html.template"
+ ),
+ outputFile: path.join(HOST_DIR, "index.html"),
+ context: { TARGET_URL }
+ } as Template);
- return mongo;
+ return mongo;
+ } catch (err) {
+ logger.error("Error occurred during startup: %s", err);
+ process.exit(1);
+ }
};
export const handleShutdown = (mongo: MongoClient, server: Server) => (