Skip to content

Commit

Permalink
RND-548 Improve error handling for PostgreSQL missing credentials (#280)
Browse files Browse the repository at this point in the history
Add validation to show a message if POSTGRES_USER and POSTGRES_PASSWORD parameters are missing in the .env file.
  • Loading branch information
jleiva-gap authored Aug 7, 2023
1 parent c41fb11 commit 1531348
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import { createDatabase, checkExistsAndCreateTables } from './SqlHelper';

let singletonDbPool: Pool | null = null;

const getDbConfiguration = () => ({
host: Config.get<string>('POSTGRES_HOST'),
port: Config.get<number>('POSTGRES_PORT'),
user: Config.get<string>('POSTGRES_USER'),
password: Config.get<string>('POSTGRES_PASSWORD'),
database: Config.get<string>('MEADOWLARK_DATABASE_NAME'),
});
const getDbConfiguration = () => {
if (!Config.get<string>('POSTGRES_USER') || !Config.get<string>('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<string>('POSTGRES_HOST'),
port: Config.get<number>('POSTGRES_PORT'),
user: Config.get<string>('POSTGRES_USER'),
password: Config.get<string>('POSTGRES_PASSWORD'),
database: Config.get<string>('MEADOWLARK_DATABASE_NAME'),
};
return dbConfiguration;
};

const moduleName = 'postgresql.repository.Db';

Expand Down

0 comments on commit 1531348

Please sign in to comment.