Skip to content

Commit

Permalink
Empêche les erreurs du MattermostNotifier d'interrompre les autres op…
Browse files Browse the repository at this point in the history
…érations
  • Loading branch information
florimondmanca committed Dec 4, 2024
1 parent dc4ebe0 commit a2e185f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export class CreateNotificationCommandHandler {
) {}

public async execute(command: CreateNotificationCommand): Promise<string> {
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<string> {
const { message, type, leaveReaquest } = command;

if (type === NotificationType.POST) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class NotificationFailureException extends Error {}
10 changes: 5 additions & 5 deletions src/Infrastructure/Adapter/MattermostNotifier.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -29,7 +30,7 @@ export class MattermostNotifier implements IMattermostNotifier {

return response.data;
} catch (e) {
throw new InternalServerErrorException(e);
throw new NotificationFailureException(e);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -85,7 +85,7 @@ export class MattermostNotifier implements IMattermostNotifier {

return response.data;
} catch (e) {
throw new InternalServerErrorException(e);
throw new NotificationFailureException(e);
}
}
}

0 comments on commit a2e185f

Please sign in to comment.