feat(application): map closing outcomes to API exceptions
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using DigitalData.TaskFlow.Domain.Enums;
|
||||
|
||||
namespace DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an API-facing exception that carries HTTP and domain meta information.
|
||||
/// </summary>
|
||||
public class ApiException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code to return.</param>
|
||||
/// <param name="metaCode">Domain meta code to return.</param>
|
||||
/// <param name="message">Response message.</param>
|
||||
public ApiException(int statusCode, MetaCode metaCode, string message)
|
||||
: base(message)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
MetaCode = metaCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP status code.
|
||||
/// </summary>
|
||||
public int StatusCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the domain meta code.
|
||||
/// </summary>
|
||||
public MetaCode MetaCode { get; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using DigitalData.TaskFlow.Domain.Enums;
|
||||
|
||||
namespace DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a 409 API exception.
|
||||
/// </summary>
|
||||
public sealed class ConflictApiException : ApiException
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ConflictApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="metaCode">Domain meta code to return.</param>
|
||||
/// <param name="message">Response message.</param>
|
||||
public ConflictApiException(MetaCode metaCode, string message)
|
||||
: base(409, metaCode, message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using DigitalData.TaskFlow.Domain.Enums;
|
||||
|
||||
namespace DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a 404 API exception.
|
||||
/// </summary>
|
||||
public sealed class NotFoundApiException : ApiException
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NotFoundApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">Response message.</param>
|
||||
public NotFoundApiException(string message)
|
||||
: base(404, MetaCode.NotFound, message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using DigitalData.TaskFlow.Application.Common.Factories;
|
||||
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
||||
using DigitalData.TaskFlow.Domain.Common;
|
||||
using DigitalData.TaskFlow.Domain.Documents;
|
||||
using DigitalData.TaskFlow.Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
||||
using DigitalData.TaskFlow.Application.Common.Factories;
|
||||
using AutoMapper;
|
||||
using DigitalData.TaskFlow.Domain.Closing;
|
||||
using DigitalData.TaskFlow.Domain.Common;
|
||||
using DigitalData.TaskFlow.Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
@@ -77,6 +79,16 @@ public sealed class CloseWorkflowCommandHandler(IWorkflowRepository workflowRepo
|
||||
decision,
|
||||
cancellationToken);
|
||||
|
||||
if (result.ProcessId <= 0)
|
||||
{
|
||||
throw new NotFoundApiException("Vorgang nicht gefunden");
|
||||
}
|
||||
|
||||
if (!result.IsClosed)
|
||||
{
|
||||
throw new ConflictApiException(MetaCode.AlreadyClosed, "Vorgang bereits abgeschlossen");
|
||||
}
|
||||
|
||||
return ApiEnvelopeFactory.Create(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user