From 07ce6ccfe1f574ed9107fb7f04654de89b7dc536 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 21 Oct 2026 19:07:35 +0200 Subject: [PATCH] Use AuthorizationException for domain-specific errors Replaced UnauthorizedAccessException with a custom AuthorizationException in SignPdfByEnvelopeCommandHandler to provide more meaningful error handling. Added the EnvelopeGenerator.Domain.Exceptions namespace to support this change. --- .../PdfSigning/SignPdfByEnvelopeCommand.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EnvelopeGenerator.Application/PdfSigning/SignPdfByEnvelopeCommand.cs b/EnvelopeGenerator.Application/PdfSigning/SignPdfByEnvelopeCommand.cs index e94298c3..3ce35e81 100644 --- a/EnvelopeGenerator.Application/PdfSigning/SignPdfByEnvelopeCommand.cs +++ b/EnvelopeGenerator.Application/PdfSigning/SignPdfByEnvelopeCommand.cs @@ -2,6 +2,7 @@ using DigitalData.Core.Exceptions; using EnvelopeGenerator.Application.Common.Query; using EnvelopeGenerator.Domain.Entities; +using EnvelopeGenerator.Domain.Exceptions; using MediatR; using Microsoft.EntityFrameworkCore; @@ -55,7 +56,7 @@ public class SignPdfByEnvelopeCommandHandler(IRepository Repo, ISender ?? throw new NotFoundException($"Envelope is not found ID: {request.Id} UUID: {request.Uuid}"); if (request.UserId is int userId && userId != envelope.UserId) - throw new UnauthorizedAccessException($"Envelope is not authorized for user with Id: {request.UserId} Envelope ID: {request.Id} UUID: {request.Uuid}"); + throw new AuthorizationException($"Envelope is not authorized for user with Id: {request.UserId} Envelope ID: {request.Id} UUID: {request.Uuid}"); if (envelope.EnvelopeReceivers.Count == 0) throw new NotFoundException($"Envelope has no receivers to sign ID: {request.Id} UUID: {request.Uuid}");