diff --git a/src/modules/workspaces/interceptors/workspaces-logs.interceptor.spec.ts b/src/modules/workspaces/interceptors/workspaces-logs.interceptor.spec.ts index e061d24d..bd6bf368 100644 --- a/src/modules/workspaces/interceptors/workspaces-logs.interceptor.spec.ts +++ b/src/modules/workspaces/interceptors/workspaces-logs.interceptor.spec.ts @@ -88,6 +88,37 @@ describe('WorkspacesLogsInterceptor', () => { '[WORKSPACE/LOGS] Invalid log action: INVALID_ACTION', ); }); + + it('When handleAction fails then should log an error', async () => { + Reflect.defineMetadata( + 'workspaceLogAction', + WorkspaceLogType.Login, + mockHandler, + ); + + const next: CallHandler = { + handle: jest.fn().mockReturnValue(of({})), + }; + + const handleActionSpy = jest + .spyOn(interceptor, 'handleAction') + .mockRejectedValueOnce(new Error('Logging failed')); + + const logErrorSpy = jest.spyOn(Logger, 'error').mockImplementation(); + + await lastValueFrom(interceptor.intercept(context, next)); + + expect(handleActionSpy).toHaveBeenCalled(); + expect(logErrorSpy).toHaveBeenCalledWith( + expect.stringContaining('Error logging action: Logging failed'), + ); + expect(logErrorSpy).toHaveBeenCalledWith( + expect.stringContaining(`Platform: ${WorkspaceLogPlatform.Web}`), + ); + expect(logErrorSpy).toHaveBeenCalledWith( + expect.stringContaining(`Action: ${WorkspaceLogType.Login}`), + ); + }); }); describe('handleAction()', () => { diff --git a/src/modules/workspaces/interceptors/workspaces-logs.interceptor.ts b/src/modules/workspaces/interceptors/workspaces-logs.interceptor.ts index 27daf0aa..e19eb624 100644 --- a/src/modules/workspaces/interceptors/workspaces-logs.interceptor.ts +++ b/src/modules/workspaces/interceptors/workspaces-logs.interceptor.ts @@ -88,7 +88,13 @@ export class WorkspacesLogsInterceptor implements NestInterceptor { return next.handle().pipe( tap((res) => { - this.handleAction(platform, this.logAction, request, res); + this.handleAction(platform, this.logAction, request, res).catch((err) => + Logger.error( + `[WORKSPACE/LOGS] Error logging action: ${ + err.message || err + }. Platform: ${platform}, Action: ${this.logAction}.`, + ), + ); }), ); }