Skip to content

Commit a6285c2

Browse files
Merge pull request #2190 from blended-bram/patch-0
fix: hide retry message when no retries will be attempted
2 parents b681904 + 531584b commit a6285c2

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/common/mongoose.utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Logger } from '@nestjs/common';
2-
import { Observable } from 'rxjs';
3-
import { delay, retryWhen, scan } from 'rxjs/operators';
4-
import { DEFAULT_DB_CONNECTION } from '../mongoose.constants';
1+
import { Logger } from "@nestjs/common";
2+
import { Observable } from "rxjs";
3+
import { delay, retryWhen, scan } from "rxjs/operators";
4+
import { DEFAULT_DB_CONNECTION } from "../mongoose.constants";
55

66
export function getModelToken(model: string, connectionName?: string) {
77
if (connectionName === undefined) {
@@ -29,12 +29,17 @@ export function handleRetry(
2929
scan((errorCount, error) => {
3030
const verboseMessage = verboseRetryLog
3131
? ` Message: ${error.message}.`
32-
: '';
32+
: "";
33+
const retryMessage = retryAttempts > 0
34+
? ` Retrying (${errorCount + 1})...`
35+
: "";
3336

3437
logger.error(
35-
`Unable to connect to the database.${verboseMessage} Retrying (${
36-
errorCount + 1
37-
})...`,
38+
[
39+
"Unable to connect to the database.",
40+
verboseMessage,
41+
retryMessage,
42+
].join(""),
3843
error.stack,
3944
);
4045
if (errorCount + 1 >= retryAttempts) {

0 commit comments

Comments
 (0)