From 17abc5cb84f3e28d030f219700fe484307b28a31 Mon Sep 17 00:00:00 2001 From: saurabhg22 Date: Wed, 8 May 2024 15:04:07 +0530 Subject: [PATCH 1/2] fix initDatabase function by proper use of await in try catch --- packages/server/src/index.ts | 51 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 387460cb95f..9947a277533 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -43,40 +43,39 @@ export class App { async initDatabase() { // Initialize database - this.AppDataSource.initialize() - .then(async () => { - logger.info('📦 [server]: Data Source is initializing...') + try { + await this.AppDataSource.initialize(); + logger.info('📦 [server]: Data Source is initializing...') - // Run Migrations Scripts - await this.AppDataSource.runMigrations({ transaction: 'each' }) + // Run Migrations Scripts + await this.AppDataSource.runMigrations({ transaction: 'each' }) - // Initialize nodes pool - this.nodesPool = new NodesPool() - await this.nodesPool.initialize() + // Initialize nodes pool + this.nodesPool = new NodesPool() + await this.nodesPool.initialize() - // Initialize chatflow pool - this.chatflowPool = new ChatflowPool() + // Initialize chatflow pool + this.chatflowPool = new ChatflowPool() - // Initialize API keys - await getAPIKeys() + // Initialize API keys + await getAPIKeys() - // Initialize encryption key - await getEncryptionKey() + // Initialize encryption key + await getEncryptionKey() - // Initialize Rate Limit - const AllChatFlow: IChatFlow[] = await getAllChatFlow() - await initializeRateLimiter(AllChatFlow) + // Initialize Rate Limit + const AllChatFlow: IChatFlow[] = await getAllChatFlow() + await initializeRateLimiter(AllChatFlow) - // Initialize cache pool - this.cachePool = new CachePool() + // Initialize cache pool + this.cachePool = new CachePool() - // Initialize telemetry - this.telemetry = new Telemetry() - logger.info('📦 [server]: Data Source has been initialized!') - }) - .catch((err) => { - logger.error('❌ [server]: Error during Data Source initialization:', err) - }) + // Initialize telemetry + this.telemetry = new Telemetry() + logger.info('📦 [server]: Data Source has been initialized!') + } catch (error) { + logger.error('❌ [server]: Error during Data Source initialization:', error); + } } async config(socketIO?: Server) { From 51f673aaa19a4feb366c7d6fa024cf348cfea862 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Thu, 9 May 2024 16:04:37 +0100 Subject: [PATCH 2/2] lint-fix --- packages/server/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 9947a277533..36bfd3d1f06 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -44,7 +44,7 @@ export class App { async initDatabase() { // Initialize database try { - await this.AppDataSource.initialize(); + await this.AppDataSource.initialize() logger.info('📦 [server]: Data Source is initializing...') // Run Migrations Scripts @@ -74,7 +74,7 @@ export class App { this.telemetry = new Telemetry() logger.info('📦 [server]: Data Source has been initialized!') } catch (error) { - logger.error('❌ [server]: Error during Data Source initialization:', error); + logger.error('❌ [server]: Error during Data Source initialization:', error) } }