Improve validation and error handling in AnnotationBehavior
Updated `using` directives to include `DigitalData.Core.Exceptions` for enhanced exception handling. Updated the `[Obsolete]` attribute message to reflect PSPDFKit library deprecation. Renamed `cancellationToken` to `cancel` for consistency. Added validation to ensure `PsPdfKitAnnotation` is only supported for the `LegacyWeb` receiver type. Introduced stricter checks for missing or invalid annotation data, throwing `BadRequestException` when necessary. Updated `await next` calls to use the renamed parameter. These changes improve code clarity, enforce stricter validation, and enhance error handling.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using DigitalData.Core.Exceptions;
|
||||||
using EnvelopeGenerator.Application.Common.Dto;
|
using EnvelopeGenerator.Application.Common.Dto;
|
||||||
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
@@ -10,13 +11,13 @@ namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
|||||||
/// Pipeline behavior that saves annotations.
|
/// Pipeline behavior that saves annotations.
|
||||||
/// Executes first in the signing process.
|
/// Executes first in the signing process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Obsolete("This notification is deprecated. Use Signature.Commands.SignCommand instead.")]
|
[Obsolete("The PSPDFKit library is deprecated.")]
|
||||||
public class AnnotationBehavior : IPipelineBehavior<SigningCommand, Unit>
|
public class AnnotationBehavior : IPipelineBehavior<SigningCommand, Unit>
|
||||||
{
|
{
|
||||||
private readonly IRepository<ElementAnnotation> _repo;
|
private readonly IRepository<ElementAnnotation> _repo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Initializes a new instance of the <see cref="AnnotationBehavior"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repository"></param>
|
/// <param name="repository"></param>
|
||||||
public AnnotationBehavior(IRepository<ElementAnnotation> repository)
|
public AnnotationBehavior(IRepository<ElementAnnotation> repository)
|
||||||
@@ -29,13 +30,21 @@ public class AnnotationBehavior : IPipelineBehavior<SigningCommand, Unit>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="next"></param>
|
/// <param name="next"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Unit> Handle(SigningCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancellationToken)
|
public async Task<Unit> Handle(SigningCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
if (request.PsPdfKitAnnotation is PsPdfKitAnnotation annot)
|
if(request.ReceiverAppType != ReceiverAppType.LegacyWeb)
|
||||||
await _repo.CreateAsync(annot.Structured, cancellationToken);
|
if(request.PsPdfKitAnnotation is null)
|
||||||
|
return await next(cancel);
|
||||||
|
else
|
||||||
|
throw new BadRequestException("PsPdfKit Annotation are only supported for the legacy web receiver type.");
|
||||||
|
|
||||||
return await next(cancellationToken);
|
if (request.PsPdfKitAnnotation is PsPdfKitAnnotation annot)
|
||||||
|
await _repo.CreateAsync(annot.Structured, cancel);
|
||||||
|
else
|
||||||
|
throw new BadRequestException("Annotation data is missing or invalid.");
|
||||||
|
|
||||||
|
return await next(cancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user