Skip to content

Commit 2485c13

Browse files
fix: improve logger for async consumer (#28)
* Fix error not propagated in Distributed Consumer (#27) * fix: improve and fix logger for async consumer --------- Co-authored-by: Julien lafont <155448870+julienlafont-shine@users.noreply.github.com>
1 parent fa6f3e4 commit 2485c13

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/channel/channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { ChannelConfig } from '../config';
33
export class Channel<T extends ChannelConfig> {
44
constructor(public readonly config: T) {}
55

6-
async onChannelDestroy(): Promise<void> {};
6+
async onChannelDestroy(): Promise<void> {}
77
}

src/consumer/distributed.consumer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class DistributedConsumer {
104104
Log.create(
105105
`Some error occurred in channel [${channel.config.name}]`,
106106
{
107-
error: e,
107+
error: e instanceof Error ? e.message : String(e),
108108
message: JSON.stringify(consumerMessage.message),
109109
routingKey: consumerMessage.routingKey,
110110
},

src/messaging.module.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
FactoryProvider,
44
Logger as NestCommonLogger,
55
Module,
6-
OnApplicationBootstrap, OnApplicationShutdown, OnModuleDestroy,
6+
OnApplicationBootstrap,
7+
OnApplicationShutdown,
8+
OnModuleDestroy,
79
Provider,
810
} from '@nestjs/common';
911
import {
@@ -44,7 +46,9 @@ import { ExceptionListenerRegistry } from './exception-listener/exception-listen
4446
import { ExceptionListenerHandler } from './exception-listener/exception-listener-handler';
4547

4648
@Module({})
47-
export class MessagingModule implements OnApplicationBootstrap, OnModuleDestroy {
49+
export class MessagingModule
50+
implements OnApplicationBootstrap, OnModuleDestroy
51+
{
4852
static forRoot(options: MessagingModuleOptions): DynamicModule {
4953
const channels = options.channels ?? [];
5054

@@ -240,7 +244,9 @@ export class MessagingModule implements OnApplicationBootstrap, OnModuleDestroy
240244
}
241245

242246
async onModuleDestroy(): Promise<any> {
243-
const channels: Channel<ChannelConfig>[] = this.moduleRef.get(Service.CHANNELS);
247+
const channels: Channel<ChannelConfig>[] = this.moduleRef.get(
248+
Service.CHANNELS,
249+
);
244250

245251
for (const channel of channels) {
246252
await channel.onChannelDestroy();

0 commit comments

Comments
 (0)