From f3af30c67d665015204fb20bc212708f5de0bf95 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 22 Oct 2025 13:10:38 +0200 Subject: [PATCH] feat(DocSignedNotificationExtensions): add PublishSafely extension for DocSignedNotification - Introduced PublishSafely method to safely publish DocSignedNotification events. - Added fallback logic to publish RemoveSignatureNotification when publishing fails. - Added missing using directive for RemoveSignatureNotification namespace. --- .../DocSigned/DocSignedNotification.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs index 50874c56..c61dea39 100644 --- a/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs +++ b/EnvelopeGenerator.Application/Common/Notifications/DocSigned/DocSignedNotification.cs @@ -1,6 +1,7 @@ using EnvelopeGenerator.Application.Common.Dto; using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver; using EnvelopeGenerator.Application.Common.Extensions; +using EnvelopeGenerator.Application.Common.Notifications.RemoveSignature; using EnvelopeGenerator.Domain.Constants; using MediatR; using System.Dynamic; @@ -60,4 +61,28 @@ public static class DocSignedNotificationExtensions /// public static async Task ToDocSignedNotification(this Task dtoTask, PsPdfKitAnnotation psPdfKitAnnotation) => await dtoTask is EnvelopeReceiverDto dto ? new(dto) { PsPdfKitAnnotation = psPdfKitAnnotation } : null; + + /// + /// + /// + /// + /// + /// + /// + public static async Task PublishSafely(this IPublisher publisher, DocSignedNotification notification, CancellationToken cancel = default) + { + try + { + await publisher.Publish(notification, cancel); + } + catch (Exception) + { + await publisher.Publish(new RemoveSignatureNotification() + { + EnvelopeId = notification.EnvelopeId, + ReceiverId = notification.ReceiverId + }, cancel); + throw; + } + } } \ No newline at end of file