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.
This commit is contained in:
@@ -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<Envelope> 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}");
|
||||
|
||||
Reference in New Issue
Block a user