Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empêche les erreurs du MattermostNotifier d'interrompre les autres opérations #451

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading