#Saga error handling unhandledExceptionBus
1 messages · Page 1 of 1 (latest)
No @Injectable() any constructor?
@Module({
imports: [
ContextModule.register(),
CqrsEventStoreModule.register(
eventStoreConnectionConfig,
mergeEsConfigs(
ReportServiceConfig,
ReportAdGroupServiceConfig
),
eventBusConfig({
...ReportSubscriptions,
...ReportAdGrouptSubscriptions,
})
),
...ReportImports,
...ReportAdGroupImports,
],
providers: [
...ReportProviders,
...ReportAdGroupProviders,
],
})
export class ReportCoreModule extends CQRSUnhandledException {}
based on kamil's comment on https://github.com/nestjs/cqrs/issues/409 last post. i created this in a module. thats what i understood but this CQRSUnhandledException class is just a listener i am getting an error when nestjs cqrs tries to .publish()
or the better question would be
- CQRSUnhandledException should be a service? so i'll add @Injectable() and add it to modules provider.
- do i need to include this service in saga class?
Wait a moment, so your module is what is extending this provider class?
CQRSUnhandledException should be a service?
Yes
so i'll add @Injectable() and add it to modules provider.
I'd suggest actually making a dedicated provider class
could you please explain a little what you mean by dedicated provider class? any reference example?
or usage so i can understand D:
@Injectable()
export class ReportCoreService extends CQRS UnhandledExcetpion {}
Then add it to the providers array
import { Inject, Injectable, Logger } from '@nestjs/common';
import { UnhandledExceptionBus, UnhandledExceptionInfo } from '@nestjs/cqrs';
import { Subject, takeUntil } from 'rxjs';
export abstract class CQRSUnhandledException {
protected readonly destroy$ = new Subject<void>();
protected readonly logger = new Logger(this.constructor.name);
constructor(
@Inject(UnhandledExceptionBus)
private readonly unhandledExceptionsBus: UnhandledExceptionBus
) {
this.unhandledExceptionsBus
.pipe(takeUntil(this.destroy$))
.subscribe(({ cause, exception }: UnhandledExceptionInfo) => {
this.logger.error(
`${exception.message}`,
exception.toString(),
`${cause.constructor.name}`
);
});
}
onModuleDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
@Injectable()
export class ReportCoreService extends CQRSUnhandledException {}
....
providers: [
...ReportProviders,
...ReportAdGroupProviders,
ReportCoreService,
],
})
export class ReportCoreModule {}
same issue
Any chance you can put this in a git repo so I can see it locally?
do i need to include this service in saga itself ?
sure
it might be difficult because im using eventstore db and setting that up and all will be pain
i found the issue, it was the 3rd party package i was using which was extending eventbus and wasnt up to date 🙂 thank you for your help!
question now, does this mean within saga i cannot use catchError() ? it seems saga's are ignoring catchError's and directly going to unhandled exception service