Skip to content

Commit

Permalink
Merge pull request #2190 from blended-bram/patch-0
Browse files Browse the repository at this point in the history
fix: hide retry message when no retries will be attempted
  • Loading branch information
kamilmysliwiec authored Oct 21, 2024
2 parents b681904 + 531584b commit a6285c2
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 a6285c2

Please sign in to comment.