Skip to content
Snippets Groups Projects
Commit 42b71e38 authored by fu1106jv's avatar fu1106jv
Browse files

Merge branch '24-specify-env-error-message-which-var-is-missing' into 'main'

Improved ErrorHandling EnvVars

Closes #24

See merge request swp-ws21-fahrtenbuch/team-einhorn/fahrtenbuch!15
parents 5001241a a82f7384
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,9 @@ EMAIL_SERVER=smtp.example.com
EMAIL_IS_TLS=false
EMAIL_USERNAME=username
EMAIL_PASSWORD=pw
EMAIL_Port=2525
EMAIL_FROM_ADDR=username@example.com
Application_Name=Fahrtenbuch Wassersportzentrum
JWT_SECRET=RANDOM_SECRET_HARD_TO_GUESS
INITIAL_COORDINATOR_PASSWORD=password
INITIAL_COORDINATOR_EMAIL=coord@example.com
......@@ -10,11 +10,12 @@ const envVars = {
INITIAL_COORDINATOR_PASSWORD: process.env.INITIAL_COORDINATOR_PASSWORD,
INITIAL_COORDINATOR_EMAIL: process.env.INITIAL_COORDINATOR_EMAIL,
};
if (Object.values(envVars).some((value) => value === undefined)) {
console.error(
"Error while reading DB Environment variables! Is maybe the .env file missing?"
);
if (Object.values(envVars).every((value) => value === undefined)){
console.error("Error while reading DB Environment variables! Is maybe the .env file missing?");
process.exit(9);
} else if (Object.values(envVars).findIndex((value) => value === undefined) != -1) {
let missingVars = Object.entries(envVars).filter(([key,value])=> value === undefined);
console.error(`Error while reading DB Environment variables!\n ${missingVars.map(x=>" - " + x[0] + "is missing.\n")} `);
process.exit(9);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment