From 1531348076c8f3d5787d2b1b75e7579b32217b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Alberto=20Leiva=20Obando?= <56046999+jleiva-gap@users.noreply.github.com> Date: Mon, 7 Aug 2023 08:39:09 -0600 Subject: [PATCH] RND-548 Improve error handling for PostgreSQL missing credentials (#280) Add validation to show a message if POSTGRES_USER and POSTGRES_PASSWORD parameters are missing in the .env file. --- .../src/repository/Db.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/src/repository/Db.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/src/repository/Db.ts index 8964791c..d2613868 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/src/repository/Db.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/src/repository/Db.ts @@ -10,13 +10,19 @@ import { createDatabase, checkExistsAndCreateTables } from './SqlHelper'; let singletonDbPool: Pool | null = null; -const getDbConfiguration = () => ({ - host: Config.get('POSTGRES_HOST'), - port: Config.get('POSTGRES_PORT'), - user: Config.get('POSTGRES_USER'), - password: Config.get('POSTGRES_PASSWORD'), - database: Config.get('MEADOWLARK_DATABASE_NAME'), -}); +const getDbConfiguration = () => { + if (!Config.get('POSTGRES_USER') || !Config.get('POSTGRES_PASSWORD')) { + throw new Error('The POSTGRES_USER and POSTGRES_PASSWORD parameters in the .env file are required and cannot be empty.'); + } + const dbConfiguration = { + host: Config.get('POSTGRES_HOST'), + port: Config.get('POSTGRES_PORT'), + user: Config.get('POSTGRES_USER'), + password: Config.get('POSTGRES_PASSWORD'), + database: Config.get('MEADOWLARK_DATABASE_NAME'), + }; + return dbConfiguration; +}; const moduleName = 'postgresql.repository.Db';