Skip to content

Commit

Permalink
fix: hide retry message when no retries will be attempted
Browse files Browse the repository at this point in the history
  • Loading branch information
blended-bram authored Jul 11, 2024
1 parent 344f2ab commit 531584b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/common/mongoose.utils.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 531584b

Please sign in to comment.