Skip to content
Snippets Groups Projects
Commit 99162d44 authored by stevereis's avatar stevereis
Browse files

Manage missing connector

parent dfb3d6fb
No related branches found
No related tags found
No related merge requests found
import { HttpModule, HttpService } from '@nestjs/axios'; 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 { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path'; import { join } from 'path';
import { ENGINE_MODULE_OPTIONS, ENGINE_SERVICE } from './engine.constants'; import { ENGINE_MODULE_OPTIONS, ENGINE_SERVICE } from './engine.constants';
...@@ -10,6 +10,8 @@ import { EngineResolver } from './engine.resolver'; ...@@ -10,6 +10,8 @@ import { EngineResolver } from './engine.resolver';
@Global() @Global()
@Module({}) @Module({})
export class EngineModule { export class EngineModule {
private static readonly logger = new Logger(EngineModule.name);
static async forRootAsync(options: IEngineOptions): Promise<DynamicModule> { static async forRootAsync(options: IEngineOptions): Promise<DynamicModule> {
const optionsProvider = { const optionsProvider = {
provide: ENGINE_MODULE_OPTIONS, provide: ENGINE_MODULE_OPTIONS,
...@@ -42,8 +44,20 @@ export class EngineModule { ...@@ -42,8 +44,20 @@ export class EngineModule {
options: IEngineOptions, options: IEngineOptions,
httpService: HttpService, httpService: HttpService,
): Promise<IEngineService> { ): 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...
}
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment