From a1e85750180e81a5c34b86ff908086922e92485d Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 20 Jul 2026 16:32:19 +0200 Subject: [PATCH] refactor(api): remove generic exception handling from middleware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Middleware/ExceptionHandlingMiddleware.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/DocumentOperator.API/Middleware/ExceptionHandlingMiddleware.cs b/DocumentOperator.API/Middleware/ExceptionHandlingMiddleware.cs index 24e1ce8..765bb7f 100644 --- a/DocumentOperator.API/Middleware/ExceptionHandlingMiddleware.cs +++ b/DocumentOperator.API/Middleware/ExceptionHandlingMiddleware.cs @@ -1,5 +1,4 @@ using DocumentOperator.Domain.Common.Exceptions; -using DocumentOperator.Domain.Exceptions; using FluentValidation; using Microsoft.AspNetCore.Mvc; 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 => ( HttpStatusCode.BadRequest, 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) _ => ( HttpStatusCode.InternalServerError,