diff --git a/packages/nestlogged/src/logged/override.ts b/packages/nestlogged/src/logged/override.ts index 6558e40..3feeab4 100644 --- a/packages/nestlogged/src/logged/override.ts +++ b/packages/nestlogged/src/logged/override.ts @@ -1,4 +1,4 @@ -import { Logger, ExecutionContext } from '@nestjs/common'; +import { Logger, ExecutionContext, ArgumentsHost } from '@nestjs/common'; import { LoggedParamReflectData, ReturnsReflectData } from '../reflected'; import { LoggedMetadata } from './metadata'; import { @@ -26,7 +26,7 @@ export function overrideBuild, R>( route: string, ): (...args: F) => R; export function overrideBuild, R>( - type: 'function' | 'guard' | 'interceptor' | 'middleware', + type: 'function' | 'guard' | 'interceptor' | 'middleware' | 'exception', originalFunction: (...args: F) => R, _target: any, metadatas: FunctionMetadata, @@ -98,6 +98,16 @@ export function overrideBuild, R>( [name, key], req[REQUEST_LOG_ID], ); + } else if (type === 'exception') { + const req = (args[1] as ArgumentsHost).switchToHttp().getRequest(); + if (req[REQUEST_LOG_ID] === undefined) { + req[REQUEST_LOG_ID] = ScopedLogger.createScopeId(); + } + args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot( + baseLogger, + [name, key], + req[REQUEST_LOG_ID], + ); } else if (type === 'route') { // args[metadatas.scopedLoggerInjectableParam] is now Request object, thanks to code in @LoggedRoute!!!! let req = args[metadatas.scopedLoggerInjectableParam]; diff --git a/packages/nestlogged/src/logged/utils.ts b/packages/nestlogged/src/logged/utils.ts index 6e6d2ad..0dd3f61 100644 --- a/packages/nestlogged/src/logged/utils.ts +++ b/packages/nestlogged/src/logged/utils.ts @@ -32,7 +32,8 @@ export type BuildType = | 'function' | 'guard' | 'interceptor' - | 'middleware'; + | 'middleware' + | 'exception'; const callLogIdentifyMessageDictionary: Record = { route: 'ENDPOINT', @@ -40,6 +41,7 @@ const callLogIdentifyMessageDictionary: Record = { guard: 'GUARD', interceptor: 'INTERCEPTOR', middleware: 'MIDDLEWARE', + exception: 'EXCEPTION FILTER', }; export function createCallLogIdentifyMessage(