-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add try-catch block in archieve controller
- Loading branch information
1 parent
319d361
commit 4063b81
Showing
1 changed file
with
18 additions
and
3 deletions.
There are no files selected for viewing
21 changes: 18 additions & 3 deletions
21
apps/api/src/modules/archived-notifications/archived-notifications.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |