From 531584b3754b9004d48146480afdadc3b083db59 Mon Sep 17 00:00:00 2001 From: Blended Bram Date: Thu, 11 Jul 2024 14:41:27 +0200 Subject: [PATCH] fix: hide retry message when no retries will be attempted --- lib/common/mongoose.utils.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/common/mongoose.utils.ts b/lib/common/mongoose.utils.ts index 39bbe6a5..af84b904 100644 --- a/lib/common/mongoose.utils.ts +++ b/lib/common/mongoose.utils.ts @@ -1,7 +1,7 @@ -import { Logger } from '@nestjs/common'; -import { Observable } from 'rxjs'; -import { delay, retryWhen, scan } from 'rxjs/operators'; -import { DEFAULT_DB_CONNECTION } from '../mongoose.constants'; +import { Logger } from "@nestjs/common"; +import { Observable } from "rxjs"; +import { delay, retryWhen, scan } from "rxjs/operators"; +import { DEFAULT_DB_CONNECTION } from "../mongoose.constants"; export function getModelToken(model: string, connectionName?: string) { if (connectionName === undefined) { @@ -29,12 +29,17 @@ export function handleRetry( scan((errorCount, error) => { const verboseMessage = verboseRetryLog ? ` Message: ${error.message}.` - : ''; + : ""; + const retryMessage = retryAttempts > 0 + ? ` Retrying (${errorCount + 1})...` + : ""; logger.error( - `Unable to connect to the database.${verboseMessage} Retrying (${ - errorCount + 1 - })...`, + [ + "Unable to connect to the database.", + verboseMessage, + retryMessage, + ].join(""), error.stack, ); if (errorCount + 1 >= retryAttempts) {