Skip to content

Commit

Permalink
feat: add try-catch block in archieve controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Harish-osmosys committed Jan 8, 2025
1 parent 319d361 commit 4063b81
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { Controller, Post } from '@nestjs/common';
import { Controller, HttpException, Logger, Post } from '@nestjs/common';
import { ArchivedNotificationsService } from './archived-notifications.service';

@Controller('archived-notifications')
export class ArchivedNotificationsController {
constructor(private readonly archivedNotificationService: ArchivedNotificationsService) {}
constructor(
private readonly archivedNotificationService: ArchivedNotificationsService,
private logger: Logger,
) {}

@Post('archive')
async addNotificationsToQueue(): Promise<void> {
this.archivedNotificationService.archiveCompletedNotificationsCron();
try {
this.logger.debug('Archiving completed notifications...');
await this.archivedNotificationService.archiveCompletedNotificationsCron();
this.logger.log('Notifications archived successfully.');
} catch (error) {
if (error instanceof HttpException) {
throw error;
}

this.logger.error('Error while archiving notifications');
this.logger.error(JSON.stringify(error, ['message', 'stack'], 2));
throw error;
}
}
}

0 comments on commit 4063b81

Please sign in to comment.