Add Domain project and shifted handlers to application.

This commit is contained in:
2026-07-15 16:10:00 +02:00
parent 656f545281
commit 0376b58a33
16 changed files with 229 additions and 52 deletions
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace FinancialApi;
public class DomainExceptionHandler : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
Exception exception,
CancellationToken cancellationToken)
{
// Only intercept our specific domain/validation exceptions
if (exception is InvalidOperationException or ArgumentException)
{
var problemDetails = new ProblemDetails
{
Status = StatusCodes.Status400BadRequest,
Title = "Domain Validation Error",
Detail = exception.Message,
Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"
};
httpContext.Response.StatusCode = problemDetails.Status.Value;
await httpContext.Response.WriteAsJsonAsync(problemDetails, cancellationToken);
return true;
}
return false;
}
}