diff --git a/services/api/package-lock.json b/services/api/package-lock.json index 260f78dc..49d7aa1b 100644 --- a/services/api/package-lock.json +++ b/services/api/package-lock.json @@ -13,7 +13,7 @@ "@fastify/static": "^6.10.0", "@nestjs/common": "^9.0.0", "@nestjs/core": "^9.0.0", - "@nestjs/cqrs": "^9.0.3", + "@nestjs/cqrs": "^10.0.3", "@nestjs/platform-express": "^9.0.0", "@nestjs/platform-fastify": "^9.4.0", "@nestjs/platform-socket.io": "^9.4.0", @@ -1792,15 +1792,15 @@ } }, "node_modules/@nestjs/cqrs": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/@nestjs/cqrs/-/cqrs-9.0.3.tgz", - "integrity": "sha512-hmbrqf51BVdgmnnxErnLVXfPNTEqr4Hz8DyLa9dKLIW3BuOyI5RDwJ/9sKbJ47UDBhumC5nQlNK9qk27mhqHfw==", + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/cqrs/-/cqrs-10.0.3.tgz", + "integrity": "sha512-6WiTMzZImjPC92/SC0lxt1KStr6zIvEM+OjSMLnIsD9eMafhsHvuZddSPcSBbAMry28j+M7VE8tvJDvuy2Ehkg==", "dependencies": { "uuid": "9.0.0" }, "peerDependencies": { - "@nestjs/common": "^9.0.0", - "@nestjs/core": "^9.0.0", + "@nestjs/common": "^9.0.0 || ^10.0.0", + "@nestjs/core": "^9.0.0 || ^10.0.0", "reflect-metadata": "0.1.13", "rxjs": "^7.2.0" } @@ -12146,9 +12146,9 @@ } }, "@nestjs/cqrs": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/@nestjs/cqrs/-/cqrs-9.0.3.tgz", - "integrity": "sha512-hmbrqf51BVdgmnnxErnLVXfPNTEqr4Hz8DyLa9dKLIW3BuOyI5RDwJ/9sKbJ47UDBhumC5nQlNK9qk27mhqHfw==", + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/cqrs/-/cqrs-10.0.3.tgz", + "integrity": "sha512-6WiTMzZImjPC92/SC0lxt1KStr6zIvEM+OjSMLnIsD9eMafhsHvuZddSPcSBbAMry28j+M7VE8tvJDvuy2Ehkg==", "requires": { "uuid": "9.0.0" } diff --git a/services/api/package.json b/services/api/package.json index e747cc4e..8646dff8 100644 --- a/services/api/package.json +++ b/services/api/package.json @@ -26,7 +26,7 @@ "@fastify/static": "^6.10.0", "@nestjs/common": "^9.0.0", "@nestjs/core": "^9.0.0", - "@nestjs/cqrs": "^9.0.3", + "@nestjs/cqrs": "^10.0.3", "@nestjs/platform-express": "^9.0.0", "@nestjs/platform-fastify": "^9.4.0", "@nestjs/platform-socket.io": "^9.4.0", diff --git a/services/api/src/core/logging/logging.module.ts b/services/api/src/core/logging/logging.module.ts index 4f4ae61b..5c88d9be 100644 --- a/services/api/src/core/logging/logging.module.ts +++ b/services/api/src/core/logging/logging.module.ts @@ -3,11 +3,12 @@ import { CqrsModule } from "@nestjs/cqrs"; import { CommandLogger } from "./command.logger"; import { EventLogger } from "./event.logger"; +import { UnhandledExceptionLogger } from "./unhandled-exception.logger"; @Module({ exports: [], imports: [CqrsModule], controllers: [], - providers: [CommandLogger, EventLogger], + providers: [CommandLogger, EventLogger, UnhandledExceptionLogger], }) export class LoggingModule {} diff --git a/services/api/src/core/logging/unhandled-exception.logger.ts b/services/api/src/core/logging/unhandled-exception.logger.ts new file mode 100644 index 00000000..c7f8b753 --- /dev/null +++ b/services/api/src/core/logging/unhandled-exception.logger.ts @@ -0,0 +1,19 @@ +import { Injectable } from "@nestjs/common"; +import { UnhandledExceptionBus } from "@nestjs/cqrs"; + +import { Logger } from "./domain/services/logger.service"; + +@Injectable() +export class UnhandledExceptionLogger { + private logger = new Logger(UnhandledExceptionLogger.name); + + constructor(private readonly unhandledExceptionBus: UnhandledExceptionBus) { + this.unhandledExceptionBus.subscribe((exceptionInfo) => { + this.logger.error({ + cause: exceptionInfo.cause, + error: exceptionInfo.exception, + msg: `Encountered unhandled exception ${exceptionInfo.exception.message}`, + }); + }); + } +}