diff --git a/src/Application/Notification/Command/CreateNotificationCommandHandler.ts b/src/Application/Notification/Command/CreateNotificationCommandHandler.ts index 498a9044..30836abd 100644 --- a/src/Application/Notification/Command/CreateNotificationCommandHandler.ts +++ b/src/Application/Notification/Command/CreateNotificationCommandHandler.ts @@ -22,6 +22,15 @@ export class CreateNotificationCommandHandler { ) {} public async execute(command: CreateNotificationCommand): Promise { + try { + return await this.createNotification(command); + } catch (e) { + // On avale l'exception pour éviter d'interrompre les autres traitements. + // Tant pis si la notification ne part pas, on finira bien par s'en rendre compte. + console.error('Failed to create notification:', e); + } + } + private async createNotification(command: CreateNotificationCommand): Promise { const { message, type, leaveReaquest } = command; if (type === NotificationType.POST) { diff --git a/src/Domain/Notification/Exception/NotificationFailureException.ts b/src/Domain/Notification/Exception/NotificationFailureException.ts new file mode 100644 index 00000000..7425b5e6 --- /dev/null +++ b/src/Domain/Notification/Exception/NotificationFailureException.ts @@ -0,0 +1 @@ +export class NotificationFailureException extends Error {} diff --git a/src/Infrastructure/Adapter/MattermostNotifier.ts b/src/Infrastructure/Adapter/MattermostNotifier.ts index 8253eb91..87b52939 100644 --- a/src/Infrastructure/Adapter/MattermostNotifier.ts +++ b/src/Infrastructure/Adapter/MattermostNotifier.ts @@ -1,7 +1,8 @@ import { HttpService } from '@nestjs/axios'; -import { Injectable, InternalServerErrorException } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { IMattermostNotifier } from 'src/Application/IMattermostNotifier'; +import { NotificationFailureException } from 'src/Domain/Notification/Exception/NotificationFailureException'; @Injectable() export class MattermostNotifier implements IMattermostNotifier { @@ -29,7 +30,7 @@ export class MattermostNotifier implements IMattermostNotifier { return response.data; } catch (e) { - throw new InternalServerErrorException(e); + throw new NotificationFailureException(e); } } @@ -57,8 +58,7 @@ export class MattermostNotifier implements IMattermostNotifier { return response.data; } catch (e) { - console.error('--error: ', e); - throw new InternalServerErrorException(e); + throw new NotificationFailureException(e); } } @@ -85,7 +85,7 @@ export class MattermostNotifier implements IMattermostNotifier { return response.data; } catch (e) { - throw new InternalServerErrorException(e); + throw new NotificationFailureException(e); } } }