refactor(api): remove generic exception handling from middleware

Remove FormatException/ArgumentException handling:
- These are framework exceptions, not application-specific
- May come from internal libraries (false positives for 400 Bad Request)
- Controllers now wrap Base64 conversion with BadRequestException explicitly

Remove PdfProcessingException handling:
- Exception type removed (obsolete)
- DevExpress exceptions now propagate naturally → 500 Internal Server Error

Current exception mapping:
- ValidationException (FluentValidation) → 400 Bad Request
- BadRequestException (custom) → 400 Bad Request
- NotFoundException (custom) → 404 Not Found
- SwissQrCodeNotFoundException (custom) → 404 Not Found
- All others → 500 Internal Server Error
This commit is contained in:
2026-07-20 16:32:19 +02:00
parent b4befde418
commit a1e8575018

View File

@@ -1,5 +1,4 @@
using DocumentOperator.Domain.Common.Exceptions; using DocumentOperator.Domain.Common.Exceptions;
using DocumentOperator.Domain.Exceptions;
using FluentValidation; using FluentValidation;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Net; using System.Net;
@@ -67,7 +66,7 @@ public class ExceptionHandlingMiddleware(RequestDelegate Next)
} }
), ),
// Not Found Exception (404 Not Found) // Bad Request Exception (400 Bad Request)
BadRequestException badReqEx => ( BadRequestException badReqEx => (
HttpStatusCode.BadRequest, HttpStatusCode.BadRequest,
new ProblemDetails new ProblemDetails
@@ -93,19 +92,6 @@ public class ExceptionHandlingMiddleware(RequestDelegate Next)
} }
), ),
// Swiss QR Code Not Found Exception (404 Not Found)
SwissQrCodeNotFoundException qrNotFoundEx => (
HttpStatusCode.NotFound,
new ProblemDetails
{
Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4",
Title = "Swiss QR Code Not Found",
Status = (int)HttpStatusCode.NotFound,
Detail = qrNotFoundEx.Message,
Instance = context.Request.Path
}
),
// Generic Exception (500 Internal Server Error) // Generic Exception (500 Internal Server Error)
_ => ( _ => (
HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError,