From 99162d448351806e710e5f22352416a3001414eb Mon Sep 17 00:00:00 2001 From: stevereis <stevereis93@gmail.com> Date: Wed, 13 Oct 2021 10:56:38 +0200 Subject: [PATCH] Manage missing connector --- api/src/engine/engine.module.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/api/src/engine/engine.module.ts b/api/src/engine/engine.module.ts index d23d0b5..182cecf 100644 --- a/api/src/engine/engine.module.ts +++ b/api/src/engine/engine.module.ts @@ -1,5 +1,5 @@ import { HttpModule, HttpService } from '@nestjs/axios'; -import { DynamicModule, Global, Module } from '@nestjs/common'; +import { DynamicModule, Global, Logger, Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { join } from 'path'; import { ENGINE_MODULE_OPTIONS, ENGINE_SERVICE } from './engine.constants'; @@ -10,6 +10,8 @@ import { EngineResolver } from './engine.resolver'; @Global() @Module({}) export class EngineModule { + private static readonly logger = new Logger(EngineModule.name); + static async forRootAsync(options: IEngineOptions): Promise<DynamicModule> { const optionsProvider = { provide: ENGINE_MODULE_OPTIONS, @@ -42,8 +44,20 @@ export class EngineModule { options: IEngineOptions, httpService: HttpService, ): Promise<IEngineService> { - const service = await import(`./connectors/${options.type}/main.connector`); + try { + const service = await import( + `./connectors/${options.type}/main.connector` + ); + const engine = new service.default(options, httpService); + + this.logger.log(`The connector '${options.type}' has been loaded`); - return new service.default(options, httpService); + return engine; + } catch { + this.logger.error( + `There is a problem with the connector '${options.type}'`, + ); + process.exit(); // We can't continue without an engine, shutdown the process... + } } } -- GitLab