buvanesh
buvanesh

Reputation: 1

how to prevent terminal stop when error occurs during the redis connection?

import {  Logger, Module } from '@nestjs/common';
import { SmModule } from '@edda/sm';
import { CacheModule } from '@nestjs/cache-manager';
import * as redisStore from 'cache-manager-redis-store';
import { RedisService } from 'libs/src/lib/core/services/redis.service';
import * as fs from 'fs';

@Module({
  imports: [
    SmModule,
    CacheModule.registerAsync({
      isGlobal: true,
      useFactory: async () => {
          const store = await redisStore.create({
            host: process.env['redis_host'],
            port: Number(process.env['redis_port']),
            password: process.env['redis_password'],
          });

          return { store }
      }
    })
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
[this is the image where if any error occurs](https://i.sstatic.net/x6KRYRiI.png)

in my project , i connect the redis in the module using useFactory . in this if any error occur in redis it was holds my application and stoped the terminal. and also i use the try catch and global exception .but none of the did not give result.how can i prevent stop from the application in production.

etc error types:

  1. timeout error
  2. connection error

Upvotes: 0

Views: 25

Answers (0)

Related Questions