Skip to content

Commit

Permalink
Merge pull request #11001 from bittlerr/nats-server-debug-messages-fi…
Browse files Browse the repository at this point in the history
…lter

refactor(microservices): use switch case for types of statuses in server
  • Loading branch information
kamilmysliwiec authored Feb 2, 2023
2 parents d9c394b + 1f327ef commit 664510a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions packages/microservices/server/server-nats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isUndefined, isObject } from '@nestjs/common/utils/shared.utils';
import { Observable } from 'rxjs';
import { NATS_DEFAULT_URL, NO_MESSAGE_HANDLER } from '../constants';
import { NatsContext } from '../ctx-host/nats.context';
import { NatsRequestJSONDeserializer } from '../deserializers/nats-request-json.deserializer';
Expand Down Expand Up @@ -137,17 +136,28 @@ export class ServerNats extends Server implements CustomTransportStrategy {
status.data && isObject(status.data)
? JSON.stringify(status.data)
: status.data;
if (status.type === 'disconnect' || status.type === 'error') {
this.logger.error(
`NatsError: type: "${status.type}", data: "${data}".`,
);
} else {
const message = `NatsStatus: type: "${status.type}", data: "${data}".`;
if (status.type === 'pingTimer') {
this.logger.debug(message);
} else {
this.logger.log(message);
}

switch (status.type) {
case 'error':
case 'disconnect':
this.logger.error(
`NatsError: type: "${status.type}", data: "${data}".`,
);
break;

case 'pingTimer':
if (this.options.debug) {
this.logger.debug(
`NatsStatus: type: "${status.type}", data: "${data}".`,
);
}
break;

default:
this.logger.log(
`NatsStatus: type: "${status.type}", data: "${data}".`,
);
break;
}
}
}
Expand Down

0 comments on commit 664510a

Please sign in to comment.